6

I am generating a dump file from a PostgreSQL database inside a Docker container which I want to be placed into the /tmp folder.

After opening a shell inside the Docker container, I then ran these commands:

sh-4.2# su - postgres
Last login: Wed Apr 18 05:22:26 UTC 2018 on pts/1
-bash-4.2$ psql
psql (9.3.15)
Type "help" for help.

I then executed this command to generate a dump file inside the /tmp folder:

postgres=# \! pg_dump -U user hidb -f /tmp/my_db_dumpa.sql;
Password: 

I gave the correct password when requested but there is no physical file inside /tmp folder in the host environment (Ubuntu Linux). Thanks

2
  • 1
    use psql to generate Commented Apr 18, 2018 at 6:14
  • Why do you start psql just to use a shell escape to launch a command? Commented Apr 18, 2018 at 6:16

1 Answer 1

4

After running docker run su - postgres and use below command.

-bash-4.2$ pg_dump -U {username of the selected db} {dbname} -f /tmp/{file name whatever you want}.sql

next execute below to see this dump file generated or not

-bash-4.2$ cd /tmp/
-bash-4.2$ ls

once confirm

open another terminal and make sure docker is running and execute below commend to copy dump file into physical file in your desktop

sudo docker cp {docker name}:/tmp/{file name of the sql file} ~/

and goto home and verify weather your dump physical file generated or not

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.