I want to run postgres inside a Docker container with a mounted volume. I am following steps as describe here. However, the container never starts. I think this is because the /var/lib/postgresql/data
directory is owned by user postgres
with uid 999
, and group postgres
with gid 999
.
My understanding is that I need to create a user and group with the same uid
and gid
on my host (the name doesn't matter), and assign these permissions to the directory I am mounting on my host.
The problem is that the uid
and gid
are already taken on my host. I can rebuild the Docker image from the Dockerfile and modify the uid
and gid
values, but I don't think this is a good long term solution as I want to be able to use the official postgres images from Docker Hub.
My question is, if a container defines permissions that already exist on the host, how do you map permission from the host to the container without having to rebuild the container itself with the configuration from your environment?
If I am misunderstanding things or am way off the mark, what is the right way to get around this problem?