Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Mounting volumes and mapping host user to docker user #22258
I want to start a docker container (postgres) and mount the folder /var/lib/postgres/data to my local system.
On my Host: ./postgres has the right owner. Nice!
Now my question.
How can I tell docker, to map my local user smith:staff to the postgres:postgres user inside the container?
btw: i also tried it with
Using this command, my postgres won't start at all.
Additional environment details (AWS, VirtualBox, physical, etc.):
Steps to reproduce the issue:
Describe the results you received:
Describe the results you expected:
Additional information you deem important (e.g. issue happens only occasionally):
The issue is the entrypoint script is expecting root access when it first starts up: https://github.com/docker-library/postgres/blob/master/9.5/docker-entrypoint.sh
In the short term it would be best to use an image that's ready to go with the correct uid/gid.
referenced this issue
Feb 15, 2017
spotted this, but not tried it yet. Looks like it might work https://denibertovic.com/posts/handling-permissions-with-docker-volumes/
I have a similar issue:
When I mount host directory and create some files/directories in it under docker it is created with a root owner.
To resolve the issue I've created all the folders and files that are created in the mounted directory, so that they have the host user owner. In addition I have to provide
Also, we can use adduser/addgroup under root and then su to the newly created user. But that would require a script that will check whether user is already created.
As you can see, mounting volumes is not without issues, as linux filesystems tend to store owner on the disk and there's no way to abstract that away using containers.
This problem can be solved by using docker-entrypoint.sh