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
Add ability to mount volume as user other than root #2259
Comments
If you
(Assuming that Another possibility is to do the bind-mount, then |
@mingfang Will chown not work for you ? |
It would be useful to have a shortcut for this. I often find myself writing https://github.com/orchardup/docker-redis/blob/07b65befbd69d9118e6c089e8616d48fe76232fd/run |
What if you don't have the rights to |
Would a helper script that |
Can I say no - forcing users to add a helper script that does
(thanks @bfirsh for your eg) is pretty terrible. It means that the container has to be started as root, rather than running as the intended and it means a user can't do something like:
|
There is one way to make it work, but you need to prepare ahead of time inside your Dockrfile.
(I didn't test this example, I'm working on a chromium container that then displays on a separate X11 container that .... ) |
And of course that method only works for direct new volumes, not bind |
Additionally, multiple containers using |
@SvenDowideit @tianon that method doesn't work either. Full example:
Two runs, with and without a -v volume:
|
We're hitting an issue that would be solved by this (I think). We have an NFS share for our developer's home directories. Developers want to mount This forbids root from accessing |
@frankamp This is because docker's current preference is to not modify host things which are not within Docker's own control. Your "VOLUME" definition is being overwritten by your I'm not sure there is much that can be done here, and unfortunately bind mounts do not support (as far as I can tell) mounting as a different uid/gid. |
My solution to this was to do what SvenDowideit did above (create new user and chown up front in dockerfile), but then instead of mounting the host volume, use a data-only container, and copy the host volume I wanted to mount into the container with |
What about acl? |
Is there any fix or workaround? I run into same issue with OpenShift, mounted folder is owned by root:root and precreated images wont work. |
I'm looking for a workaround too. If all mounted volumes are owned by |
Well you can try s6-overlay. It includes features which are specifically targeted to help to work-around these kinds of problems. |
@dreamcat4: Thanks for the pointer. The fixing ownership & permissions seems like an interesting workaround, but wouldn't I have to run my Docker container as root for that to work? |
@brikis98 Yes that is true. However s6-overlay also has yet another feature, which allows you to drop the permissions back again when launching your servers / daemons. |
@dreamcat4 Ah, gotcha, thanks. |
With 800 Thumbs Up, 100 comments telling you "hey, we need this thing badly!" a normal company would provide this feature to customers asap. |
@RobIsHere open source projects are not a company; you're welcome to contribute though. |
@RobIsHere we are happy to have at least the answer here. |
Just run docker engine in rootless mode and your host volume mounts will use whatever user you run docker as. Problem solved. There are a few gotchas with Rootless mode and I would not recommend it for any production workloads but for a local development environment it is "the shit" you are looking for. |
"Yes, but actually no." |
I recall that on a much earlier rev of docker desktop they were having problems with the filesystem glitching out under high I/O load, because essentially you have a virtual machine hosting docker, trying to access files from the host's host. The group wisdom was that you would get faster and more stable behavior by using a network filesystem to access files on the physical machine. I wonder if that solution would work here too, and what the overhead would be. |
I would just like to point out, since it's been lost in the reply churn, that this solution mentioned early in the reply chain works well, when you can control the host operating system enough to have a stable user id across the cluster. Doesn't work so good for tmpfs, but does fine for normal volumes.
Our cluster is homogeneous, so I have a base image that a couple of services and a sidecar share, which among other things handles the UID/GID mapping. |
No, because what you normally want for a dev environment is that a specific host user is mapped to a specific container user (usually the same uid, as with podman's |
Almost 10 years 🎉🥳🎉 |
in a corporate environment every developer is going to potentially have a separate UID. And even if it starts the same, there’s always fun with people changing their names, lost or stolen machines and such. That means custom config for every user which we tend to frown on. It’s bad for onboarding and a tripping hazard for everyone else. |
Normally with devcontainers, you don't have to worry about "other" users, only the initiating one. In most cases, the machine used will be their own, so won't have other users on it anyways. Outside of that, mounted volumes will usually come from their home directories. |
Its also problematic when you use secrets that should be accessible by specific user. For example And that hack to know the |
To my mind it would be ideally: |
As noted in the limitations section of tmpfs mount docs (this was added to docs in Feb 2023), you can set the UID/GID of what you'd expect it to be instead of the default # Example
$ docker run --rm -it --tmpfs "/data:exec,uid=$(id -u),gid=$(id -g),mode=0644,size=1G" alpine ash
$ apk add exa
# Mode is correctly changed, so is the UID and GID:
$ exa --octal-permissions -ldgh /data
Octal Permissions Size User Group Date Modified Name
0644 drw-r--r-- - 1000 1000 28 Sep 23:03 /data
# Size is correctly applied:
$ df -h /data
tmpfs 1.0G 0 1.0G 0% /data This PR that didn't get merged additionally notes:
Not exactly, size is 50% of Docker host by default: $ docker run --rm -it --tmpfs "/data" alpine ash
$ mount | grep /data
tmpfs on /data type tmpfs (rw,nosuid,nodev,noexec,relatime)
$ cat /proc/mounts | grep /data
tmpfs /data tmpfs rw,nosuid,nodev,noexec,relatime 0 0
$ df -h /data
Filesystem Size Used Available Use% Mounted on
tmpfs 7.6G 0 7.6G 0% /data Additionally the Docker docs on tmpfs incorrectly state:
Clearly it does support options now as shown above. |
Use case: mount a volume from host to container for use by apache as www user.
The problem is currently all mounts are mounted as root inside the container.
For example, this command
docker run -v /tmp:/var/www ubuntu stat -c "%U %G" /var/www
will print "root root"
I need to mount it as user www inside the container.
The text was updated successfully, but these errors were encountered: