Home > Blockchain >  Why is the postgres container intializing correctly with a bad mapping of the data volume?
Why is the postgres container intializing correctly with a bad mapping of the data volume?

Time:12-10

I tried to unrespect the official postgres docker hub page, just to see what happens.

And then, by replacing recommended command

docker run -e POSTGRES_PASSWORD=pg-pwd -v pg-data:/var/lib/postgres/data -d postgres

by this one, with bad path

docker run -e POSTGRES_PASSWORD=pg-pwd -v pg-data2:/var/lib/bad-path/data -d postgres

I found that it works just as well.

Why, in my second test, can the postgres server initialize, as I mapped the wrong postgres system path?

CodePudding user response:

You mapped the pg-data2 volume to some arbitrary path, but that does not make the correct path inside the container unusable. In fact, since you did not mount a volume to that path it probably created an anonymous volume which will go away once the container is deleted.

So the "error" happens when you exit and delete the container because that will also delete your database. This won't happen in the original setup because the volume persists and can be mounted into a new container.

  • Related