-
Notifications
You must be signed in to change notification settings - Fork 18.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mounting volumes and mapping host user to docker user #22258
Comments
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. |
I also want to know how to make volume mapping possible in docker-beta. When using docker-machine, I use nfs mount in the docker-machine's boot2docker. How can I mount nfs inside Alpine? |
Hi, i was facing the same problem lately. any news here? Would like to mount a host volume and make sure all files there belong to my developer user, not some unidentified user 1000. |
@blafasel42 (generally) users on the host match users in the container. If you want the host dir to have a particular UID/GID you need to set it. |
docker4mac is a slightly difference case since it does map UID/GID into the UID/GID that the container process was started with. |
I wrote a script which lets you map your userid/groupid to any user inside docker. This is a fully working example. Please try and let me know, if you have any questions :) |
@smith64fx it should not be possible to map the hosts userID to the root one's from the docker image, right (1000=>0)? I get into trouble with the script at this point: |
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 Alternatively, 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
Reference: https://eggclub.org/thay-doi-owner-cua-mount-volume-khi-dev-voi-docker/ |
FYI: http://docker-sync.io/ seems to be a good substitution for bind-mounts for as long as the ownership translation is not supported by docker natively. |
Wow, I really would have thought there would be something native in the docker-compose for mapping a host user to a container user. e.g. something like:
... where this would mean the host user with uid 1000 would get mapped to the container user 1002, and host user 1001 would get mapped to container user 1002. This is following the convention of always doing host:container with things like docker cp, and docker volume definitions. Correct me if I'm wrong and there is nothing native yet... |
no it's not there as part of regular linux installs of the docker engine; keep an eye on #2259 (most notably #2259 (comment) and the comments after that), and upvote docker/roadmap#39 with a "thumbs up" on the first comment, to prioritise "Docker Desktop for Linux" in Docker's roadmap (which would include features like this) |
The best solution I found so far is this: https://github.com/lebokus/docker-volume-bindfs . It's a docker plugin that uses FUSE to rewrite the user/group IDs. |
I have resolved this issue for me passing hardcoded well known UID and GID:
|
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!
But inside Container: /var/lib/postgresql/data has the owner root:root. the postgres user cannot access the /var/lib/postgresql/data folder...
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.
#21702
Output of
docker info
:Additional environment details (AWS, VirtualBox, physical, etc.):
Docker Beta for OSX
Steps to reproduce the issue:
1.
2.
3.
Describe the results you received:
Describe the results you expected:
Additional information you deem important (e.g. issue happens only occasionally):
The text was updated successfully, but these errors were encountered: