You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 1, 2021. It is now read-only.
Repository navigation
This repository was archived by the owner on Jan 1, 2021. It is now read-only.
1.3.0 - Only root can write to OSX volumes / Can't change permissions within #581
Currently only root inside the container is able to modify mounted volumes. Also permissions changed from within have no effect. I'm unsure as to whether cannot be managed dynamically on the blog post refers to any of this.
I would suggest updating the readme to let users know about the existence of native support for volumes and also its limitations (especially if this is one of them).
Reacted by AgBorkowski, Yaroslav, Raul, Emmanuel M. Smith🔸, iam4x, xiaozhai123, Yuliia Kostrikova, Graziele GS and Yerzhan Torgayev
I wrote up a simple test case. Let me know if there's anything else I can do to make this bug easier to fix.
First, I create a Dockerfile:
FROM ubuntu:14.04
# Adding user
RUN adduser --system --ingroup staff mugzy
# Setup repos dir.
RUN mkdir /data
RUN chown mugzy:staff -R /data
VOLUME /data
CMD touch /data/file && ls -al /data
Then create a host volume that I'll mount into the Docker instance at runtime:
app[master] → mkdir ./data
When I run the container, I see root:root ownership on the docker /data volume. I'd expect for this to be what I set from the Dockerfile above, mugzy:staff:
app[master] → docker run -i -v $PWD/data:/data c638bc43bfe7
total 4
drwxr-xr-x 1 1000 staff 102 Oct 21 2014 .
drwxr-xr-x 62 root root 4096 Oct 21 01:54 ..
-rw-r--r-- 1 1000 staff 0 Oct 21 01:49 file
Obviously when I then run the docker instance as mugzy, the volume has incorrect permissions and I can't write to disk:
app[master] → docker run -i -v $PWD/data:/data -u mugzy c638bc43bfe7
total 4
drwxr-xr-x 1 1000 staff 102 Oct 21 2014 .
drwxr-xr-x 62 root root 4096 Oct 21 01:54 ..
-rw-r--r-- 1 1000 staff 0 Oct 21 01:49 file
touch: cannot touch '/data/file': Permission denied
I'd imagine if people are trying to boot services in Docker on Mac, they'd want to be able to setup a volume that a service user can write to for persistence.
Mounting a VBox share as UID 999 will allow the created container user to write as it's usually 999. This is just a fragile hack on the hack but it does allow writing…
sudo mount -t vboxsf -o uid=999,gid=50 your-other-share-name /some/mount/location
So can I use this command to set the /Users share to be writeable?
Or do I have to create a special share for every application that needs to be able to write in a folder?
/Users is a bit special as it's mounted by the boot2docker script (any share matching the names listed in release notes), changing it requires customising the code. I just created a custom share anyway as I don't want to share the whole /Users structure with containers.
Overriding the /Users default share on boot2docker start:
boot2docker --vbox-share=$(pwd)/share-location=share-name up
boot2docker ssh in and mount the custom share:
sudo mount -t vboxsf -o uid=999,gid=50 share-name [SHARE-FULL-PATH]/share-location
Thanks for the workaround.
Although it would be great to have that behavior built into the boot2docker script (don’t want coworkers to do much extra action).
@tianon Now try with a different user and it will not work.
The big problem is that usually, Nginx or MySQL or whatever will run as a different user (www-data, mysql…) so it's impossible to use Docker at all (at least in those situations).
Permissions with volume mounts are one of those "gotchas" that's always a sticky point, so I don't see a good fix for the general case (besides Docker handling the volume sharing more directly, and thus smoothing permissions issues somehow), especially since once you've got it working for "just this one container", you're going to want to spin up another, and it will probably have different UIDs altogether (think mysql + postgres + wordpress + stuff specific to your own development, etc).
@ababushkin I have read reports from users of native Docker for Mac that they no longer need any workaround. I created the permissions script to make it work on Docker Toolbox.
@ernestom did you notice any performance improvement for disk sync when using that solution? Symfony runs really poorly for me at the moment. I have the same issue when using Vagrant and VirtualBox shared volumes and worked around it by using an NFS mount.
Update: I just noticed that the new version of docker has its own VM and a new OSX dedicated file system layer. I'll try this out to see if there are still performance issues :)
@ababushkin I didn't notice any significant impact in performance with NFS for Docker, and I've been using it for years on my vagrant/vbox projects without issues.
@ababushkin I have been using Docker for Mac for a couple of months now, and unfortunately performance issues still there for me. My case is - project on local, mounted inside container, running inside container. For example some project on Symfony, I run some heavy with high I/O app/console command and waiting tens of minutes or even hours to complete instead of up to 10 minutes on pure local.
So just to follow-up here, the issue seems to be gone on the Mac if you install the native Docker beta (use beta channel here). That obviously doesn't solve the problem much for automated scenarios, but works well for local dev.
@dend Yup thats correct, permission issues are fixed with Docker for Mac. You don't need to install the beta version, the stable release fixes it as well.
Unfortunately performance issues have not been fixed. At this stage I've been getting around performance issues by doing smarter builds of my images (e.g. mounting volumes that don't need lots of read/write operations by the app)
Just trying back to use Docke for mac with a web project, the ownership issue is still here..
Files are mounted in root:root and even if I change the ownership to www-data with a entrypoint, the new one will be created as root user.
Any idea ? I tried to use USER www-data before starting the apache process but as you know, www-data doesn't have the privilege to start the apache service.. Feel stuck :(
@vmaatta was right in his breakdown, and I'd like to add that the "issue" is the -r option in groupadd/useradd versus adding users without that specific option. The -r option creates system users, which by default (set in /etc/adduser.conf) "starts" with UID/GID 999. (Last in range.)
root@9b3da358b593:/# egrep SYSTEM /etc/adduser.conf
# FIRST_SYSTEM_[GU]ID to LAST_SYSTEM_[GU]ID inclusive is the range for UIDs
FIRST_SYSTEM_UID=100
LAST_SYSTEM_UID=999
FIRST_SYSTEM_GID=100
LAST_SYSTEM_GID=999
For regular users, these would be added starting UID/GID 1000 (matching the UID for the boot2docker docker user), which is fine for a single user. This also has the implication that if another user were to be added in a container, that a user with UID 1001 wouldn't be able to access files through vboxsf.
Right now, I don't know how this could be solved easily, but I'm going to look into this.
Recap: Images create system users that don't match the UID of the docker user in boot2docker.
@TyIsI, many of the images provided by Docker Official Images (like rabbitmq) were modified to allow running as a different user so that you would not need to create or modify the user in the image. See docker-library/rabbitmq#60 and the other PRs linked from there. What this means is that in most instances when using boot2docker on a Mac, you can do something like the following:
$ docker run -d -v /Users/myuser/rabbitdir/:/var/lib/rabbitmq/ --user 1000:50 rabbitmq:3-managment
Activity
mnapoli commentedon Oct 20, 2014
I think I'm having the same issue (latest versions of everything, installed today).
In the container, in a directory shared with the host (i.e. mounted through the virtualbox VM):
777permissionsIs that normal or not? (i.e. I did something wrong)
lukaswelte commentedon Oct 20, 2014
So means if I create a cache folder for example that writes new files and folders to disk during execution, I cannot do this right now?
Cause I experience the same problem as @mnapoli does..
bradgessler commentedon Oct 21, 2014
I wrote up a simple test case. Let me know if there's anything else I can do to make this bug easier to fix.
First, I create a Dockerfile:
Then create a host volume that I'll mount into the Docker instance at runtime:
When I run the container, I see
root:rootownership on the docker/datavolume. I'd expect for this to be what I set from the Dockerfile above,mugzy:staff:Obviously when I then run the docker instance as
mugzy, the volume has incorrect permissions and I can't write to disk:I'd imagine if people are trying to boot services in Docker on Mac, they'd want to be able to setup a volume that a service user can write to for persistence.
vmaatta commentedon Oct 22, 2014
Mounting a VBox share as UID 999 will allow the created container user to write as it's usually 999. This is just a fragile hack on the hack but it does allow writing…
lukaswelte commentedon Oct 22, 2014
So can I use this command to set the /Users share to be writeable?
Or do I have to create a special share for every application that needs to be able to write in a folder?
vmaatta commentedon Oct 22, 2014
/Users is a bit special as it's mounted by the boot2docker script (any share matching the names listed in release notes), changing it requires customising the code. I just created a custom share anyway as I don't want to share the whole /Users structure with containers.
boot2docker sshin and mount the custom share:lukaswelte commentedon Oct 22, 2014
Thanks for the workaround.
Although it would be great to have that behavior built into the boot2docker script (don’t want coworkers to do much extra action).
SvenDowideit commentedon Oct 23, 2014
@tianon ?
tianon commentedon Oct 23, 2014
This is bizarre - do we need to tweak something about the way we mount the share?
There's nothing special about what we do: https://github.com/boot2docker/boot2docker/blob/master/rootfs/rootfs/etc/rc.d/automount-shares (just
uid=...,gid=...as mentioned here)tianon commentedon Oct 23, 2014
Indeed, I've just tested here:
So I definitely need more information about what's going wrong if we're going to figure out how to fix it. 😄
mnapoli commentedon Oct 23, 2014
@tianon Now try with a different user and it will not work.
The big problem is that usually, Nginx or MySQL or whatever will run as a different user (www-data, mysql…) so it's impossible to use Docker at all (at least in those situations).
tianon commentedon Oct 23, 2014
Right, but how can we fix it?
Permissions with volume mounts are one of those "gotchas" that's always a sticky point, so I don't see a good fix for the general case (besides Docker handling the volume sharing more directly, and thus smoothing permissions issues somehow), especially since once you've got it working for "just this one container", you're going to want to spin up another, and it will probably have different UIDs altogether (think
mysql+postgres+wordpress+ stuff specific to your own development, etc).209 remaining items
motin commentedon Sep 5, 2016
@ababushkin I have read reports from users of native Docker for Mac that they no longer need any workaround. I created the permissions script to make it work on Docker Toolbox.
dgraziotin commentedon Sep 5, 2016
@ababushkin I confirm that with Docker v1.12.0 for Mac, there is no need to use my ugly workaround anymore :-) @motin
ababushkin commentedon Sep 5, 2016
@dgraziotin @motin Ouch, looks like I'm still running Docker v1.11.0.
I'll upgrade and give it a whirl.
@yosifkit thanks for the tip!
ababushkin commentedon Sep 5, 2016
@ernestom did you notice any performance improvement for disk sync when using that solution? Symfony runs really poorly for me at the moment. I have the same issue when using Vagrant and VirtualBox shared volumes and worked around it by using an NFS mount.
Update: I just noticed that the new version of docker has its own VM and a new OSX dedicated file system layer. I'll try this out to see if there are still performance issues :)
ernestom commentedon Sep 5, 2016
@ababushkin I didn't notice any significant impact in performance with NFS for Docker, and I've been using it for years on my vagrant/vbox projects without issues.
krasilich commentedon Sep 5, 2016
@ababushkin I have been using Docker for Mac for a couple of months now, and unfortunately performance issues still there for me. My case is - project on local, mounted inside container, running inside container. For example some project on Symfony, I run some heavy with high I/O app/console command and waiting tens of minutes or even hours to complete instead of up to 10 minutes on pure local.
ababushkin commentedon Sep 12, 2016
@ernestom @krasilich Thats a bummer.
@ernestom do you have a boilerplate docker-compose file that's using the NFS solution by any chance?
dend commentedon Oct 24, 2016
So just to follow-up here, the issue seems to be gone on the Mac if you install the native Docker beta (use beta channel here). That obviously doesn't solve the problem much for automated scenarios, but works well for local dev.
ababushkin commentedon Oct 24, 2016
@dend Yup thats correct, permission issues are fixed with Docker for Mac. You don't need to install the beta version, the stable release fixes it as well.
Unfortunately performance issues have not been fixed. At this stage I've been getting around performance issues by doing smarter builds of my images (e.g. mounting volumes that don't need lots of read/write operations by the app)
vschoener commentedon Apr 25, 2017
Just trying back to use Docke for mac with a web project, the ownership issue is still here..
Files are mounted in root:root and even if I change the ownership to www-data with a entrypoint, the new one will be created as root user.
Any idea ? I tried to use USER www-data before starting the apache process but as you know, www-data doesn't have the privilege to start the apache service.. Feel stuck :(
engine: Fix access to mounted volume on Docker Machine for MAC
TyIsI commentedon Sep 28, 2017
Ran into this issue as well.
@vmaatta was right in his breakdown, and I'd like to add that the "issue" is the -r option in groupadd/useradd versus adding users without that specific option. The -r option creates system users, which by default (set in /etc/adduser.conf) "starts" with UID/GID 999. (Last in range.)
For regular users, these would be added starting UID/GID 1000 (matching the UID for the boot2docker docker user), which is fine for a single user. This also has the implication that if another user were to be added in a container, that a user with UID 1001 wouldn't be able to access files through vboxsf.
Right now, I don't know how this could be solved easily, but I'm going to look into this.
Recap: Images create system users that don't match the UID of the docker user in boot2docker.
TyIsI commentedon Sep 28, 2017
Example work-around for rabbitmq:
Dockerfile:
docker build -t rabbitmq-test .docker run -d --hostname my-rabbit --name some-rabbit -p 8080:15672 -v `pwd`/data/rabbitmq/:/var/lib/rabbitmq rabbitmq-testyosifkit commentedon Sep 28, 2017
@TyIsI, many of the images provided by Docker Official Images (like
rabbitmq) were modified to allow running as a different user so that you would not need to create or modify the user in the image. See docker-library/rabbitmq#60 and the other PRs linked from there. What this means is that in most instances when using boot2docker on a Mac, you can do something like the following:$ docker run -d -v /Users/myuser/rabbitdir/:/var/lib/rabbitmq/ --user 1000:50 rabbitmq:3-managmentSome notable exceptions that don't work with the VirtualBox shared folder are MongoDB (docker-library/mongo#74 (comment)) and MariaDB 10.1 (docker-library/percona#42 (comment)).