Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upAdd 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. |
|
Docker had this particular issue open since 2013 and nearly six years later there is no easy improvement in sight. Podman was designed to gain compatibility with Docker but solve the design flaws of Docker as well (including running as an unprivileged user that won't require a superuser Docker daemon). If users are able to giver others an advice on a GitHub issue that's totally fine. This is a community. Feel free to recommend whatever could be helpful.
So is If Podman doesn't work for you: fine! But if helps others because they just have to replace |
|
Podmans main argument is that it does not run a daemon and that is my main argument against it. How do I get my container back up after a reboot? I won't do it by hand and everything else is just bad design. Also I don't want my docker container owned by a user but owned by the system and this means root. And to fix your problem: Build a container with Also Docker has not such problems and you can remotely control docker servers which is important for me, too. There are tools to generate pods from running containers, too which I won't recommend cause you should build them from the ground up in a clean way. |
|
I guess we should go back on topic now: IMHO the first advice was okay but everything else just blows this issue up and won't solve anything. @SuperSandro2000, you can click here for the response on your statements, though.
Well, Podman has native integration with systemd (like nearly every other thing on nearly all modern GNU Linux distributions). So you don't have to maintain 'two' booting systems (like first having systemd to start the Docker daemon which then have to make another round of starting containers in a different configuration). So with Podman you can control everything with systemd (meaning: the system you most probably already have installed and running anyway).
It is totally fine if you don't want it. You are still able to run Podman as superuser but you don't have to anymore. In general it is considered a bad idea and increases the attack surface because if someone is able to exploit your Docker daemon, he has control about everything on on the system.
This statement does not make any sense. Podman enables you to spread up on a single system which is a feature that especially makes sense if you have many people working on the same system.
IMHO the issue here is mounting a volume for a container on runtime. Which has only little to do with building an image.
Funny that you mention exactly the blog that has this post in it. However I'm not very experienced with network details of both implementations but as I understood, podman starts with the least possible network rules and unprivileged users cannot set up |
|
To be clear, you should be able to get the same affect with rootless docker as you get with podman.
This is because dockerd is running as your user and root in the container is mapped to your UID.
This does have drawbacks and of course does not work when sharing a daemon with multiple users.
https://get.docker.com/rootless
… On Jun 27, 2019, at 7:52 AM, Alexander Adam ***@***.***> wrote:
I guess we should go back on topic now: IMHO the first advice was okay but everything else just blows this issue up and won't solve anything.
@SuperSandro2000 <https://github.com/SuperSandro2000>, you can click here for the response on your statements, though.
<https://podman.io/blogs/2018/09/13/systemd.html> <https://osric.com/chris/accidental-developer/2018/12/docker-versus-podman-and-iptables/> <https://osric.com/chris/accidental-developer/2018/12/using-docker-to-get-root-access/>
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub <#2259?email_source=notifications&email_token=AAGDCZXX2UQCG7LUVH57V6LP4TH2DA5CNFSM4AI3DP62YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODYXL2XI#issuecomment-506379613>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AAGDCZX437HJP4M6XG3SEY3P4TH2DANCNFSM4AI3DP6Q>.
|
My solution was to no mount the directory but bake it in the container if it is possible. I mean podman sounds good but I won't switch cause for now I do not see any advantage for me. Thanks for the explanation anyway. |
|
The solution could be to map |
* It turn out there is a major unsolved problem with dockers with non root users and volumes bound to host dir: moby/moby#2259 see README.md
|
If you want to run with
Dockerfile:
Then:
Now, when running the docker image and mounting the volume, /some_dir belongs to the user I want.
|
|
I'll point out again, because it is easily lost in the thread, that a chowned symlink will probably work for most scenarios. The downside being that you need someway of setting it up, which often means replacing the entrypoint with a script that then runs the original command. |
I'm adding a lot of complication here simply because Docker doesn't allow us to creat something in a container and expose it in a volume on the host while making the files owned by the current user. More info --------- moby/moby#2259 title: Add ability to mount volume as user other than root date: 2013-10-17 https://medium.com/faun/set-current-host-user-for-docker-container-4e521cef9ffc title: Set current host user for docker container author: Lenty Chang date: 2019-04-07
|
+1 |
Happens when mounting the VM share in mount-vm-share.sh. The issue has two parts: 1. "pi" does not have write access to `/dev/fuse`, not even with sudo, so mount-vm-share.sh fails to mount the drive. 2. `/dev/fuse` does not exist until runtime so it's not accessible when building the Docker image. The easiset solution is to give back root-membership to "pi". It was removed in the switch from `useradd` to `adduser` in PR #8 (67a9067). Not the same, but there might be something to learn from Docker's requirement on root access for mounting volumes: moby/moby#2259 Note: The "pi" user on a real RetroPie installation on a RPi is _not_ member of root. So this solution should be removed one day. Cleaned up Dockerfile. The instructions will be added to Readme.
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.