Skip to content
This repository was archived by the owner on Jan 1, 2021. It is now read-only.
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

Open

Description

@lynxnathan

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).

Activity

  1. added this to the 1.3.1 milestone on Oct 20, 2014
  2. mnapoli commented on Oct 20, 2014

    @mnapoli

    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):

    • root user can write files
    • www-data user can't, even in a directory with 777 permissions

    Is that normal or not? (i.e. I did something wrong)

  3. lukaswelte commented on Oct 20, 2014

    @lukaswelte

    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..

  4. bradgessler commented on Oct 21, 2014

    @bradgessler

    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.

  5. vmaatta commented on Oct 22, 2014

    @vmaatta

    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
    
  6. lukaswelte commented on Oct 22, 2014

    @lukaswelte

    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?

  7. vmaatta commented on Oct 22, 2014

    @vmaatta

    /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.

    1. Overriding the /Users default share on boot2docker start:
    boot2docker --vbox-share=$(pwd)/share-location=share-name up
    
    1. boot2docker ssh in and mount the custom share:
    sudo mount -t vboxsf -o uid=999,gid=50 share-name [SHARE-FULL-PATH]/share-location
    
  8. lukaswelte commented on Oct 22, 2014

    @lukaswelte

    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).

  9. SvenDowideit commented on Oct 23, 2014

    @SvenDowideit
    Contributor
  10. tianon commented on Oct 23, 2014

    @tianon
    Contributor

    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)

  11. modified the milestone: 1.3.1 on Oct 23, 2014
  12. tianon commented on Oct 23, 2014

    @tianon
    Contributor

    Indeed, I've just tested here:

    docker@boot2docker:~$ ls -lAF /
    ...
    drwxr-xr-x    1 docker   staff        12288 Oct 23 16:37 Users/
    ...
    docker@boot2docker:~$ echo test > /Users/test
    docker@boot2docker:~$ cat /Users/test
    test
    docker@boot2docker:~$ rm -v /Users/test
    rm: remove '/Users/test'? y
    docker@boot2docker:~$

    So I definitely need more information about what's going wrong if we're going to figure out how to fix it. 😄

  13. mnapoli commented on Oct 23, 2014

    @mnapoli

    @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).

  14. tianon commented on Oct 23, 2014

    @tianon
    Contributor

    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).

  15. 209 remaining items

  16. motin commented on Sep 5, 2016

    @motin

    @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.

  17. dgraziotin commented on Sep 5, 2016

    @dgraziotin

    @ababushkin I confirm that with Docker v1.12.0 for Mac, there is no need to use my ugly workaround anymore :-) @motin

  18. ababushkin commented on Sep 5, 2016

    @ababushkin

    @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!

  19. ababushkin commented on Sep 5, 2016

    @ababushkin

    @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 :)

  20. ernestom commented on Sep 5, 2016

    @ernestom

    @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.

  21. krasilich commented on Sep 5, 2016

    @krasilich

    @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.

  22. ababushkin commented on Sep 12, 2016

    @ababushkin

    @ernestom @krasilich Thats a bummer.

    @ernestom do you have a boilerplate docker-compose file that's using the NFS solution by any chance?

  23. dend commented on Oct 24, 2016

    @dend

    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.

  24. ababushkin commented on Oct 24, 2016

    @ababushkin

    @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)

  25. vschoener commented on Apr 25, 2017

    @vschoener

    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 :(

  26. TyIsI commented on Sep 28, 2017

    @TyIsI

    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.)

    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.

  27. TyIsI commented on Sep 28, 2017

    @TyIsI

    Example work-around for rabbitmq:

    Dockerfile:

    FROM rabbitmq:3-management
    
    RUN usermod -u 1000 rabbitmq
    RUN groupmod -g 1000 rabbitmq
    

    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-test

  28. yosifkit commented on Sep 28, 2017

    @yosifkit
    Contributor

    @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

    Some 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)).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions