2

I found the following mentioned at many places -

docker run -d \
    --name some-postgres \
    -e POSTGRES_PASSWORD=mysecretpassword \
    -e PGDATA=/var/lib/postgresql/data/pgdata \
    -v /custom/mount:/var/lib/postgresql/data \
    postgres

My only question is that I am unable to find /var/lib/postgresql/data/pgdata directory itself. I don't see any postgresql directory under /var/lib. Why is it? And just wonder how does it work if there is no directory?

1
  • For one who voted negative on it, the following command could have helped instead docker exec -it <container name> /bin/bash. I wasn't sure that it goes inside the container just like the directories outside it. Commented May 18, 2020 at 13:40

1 Answer 1

1

The -v in your command mounts /custom/mount on your host (the machine where you run docker command) to container's /var/lib/postgresql/data. So the pgdata you are looking for is on host's /custom/mount/pgdata.

Of course, /custom/data is only an example name, you have to replace it with your real directory.

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

6 Comments

If I don't mount, where can I find /var/lib/postgresql/data ?
I have the same question, too
@infinite i have the same question: when not mounted, where can i find /var/lib/postgresql/data? did you find it?
If you don't mount a directory from your host machine, then the directory exists only inside the container. When you recreate the container, all data is lost, unless you mounted a persistent disk
@VesaKarjalainen yes i definitely understood the part you mentioned above but i'm trying to symlink /var/lib/postgresql/data to a location inside my codebase (which is persisted). The issue is i can't locate /var/lib/postgresql/data :(
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.