Docker(NGINX,PHP,mySQL)和Windows - 文件权限

I've been looking into docker for a few hours; I'm running Windows 8.1 as the host machine, and VirtualBox with boot2docker.

This is my docker-compose.yml:

mysql:
    image: mysql
    ports: 
        - "6603:3306"    
    environment:
        MYSQL_ROOT_PASSWORD: mysql
        MYSQL_USER: mysql
fpm:
    image: php:7.0.2-fpm
    volumes:
        - /c/Users/Administrator/www:/var/www/html
    ports:
        - "9000:9000"
    links:
        - mysql
nginx:
    image: nginx 
    ports:
        - "80:80"
        - "443:443"
    volumes:
        - /c/Users/Administrator/www:/var/www/html
    links:
        - fpm

This works fine (I can go to my docker ip address and see the nginx welcome page); although when I run mkdir for example (through php) it will give an error regarding windows permissions.

You should use volumes tag instead of volumes_from

  • volumes can mount directories from host machine to container and
  • volumes_from mounts directories from other services or containers

Please look at docker-compose file documentation

And your docker-compose file should look like this:

fpm:
    image: php:7.0.2-fpm
    volumes:
        - /c/Users/Administrator/www:/var/www/html
    ports:
        - "9000:9000"
    links:
        - mysql
nginx:
    image: nginx 
    ports:
        - "80:80"
        - "443:443"
    volumes_from:
        - fpm
    links:
        - fpm

This is a limitation of the way the Windows filesystem is shared with the VirtualBox Virtual Machine, using VirtualBox guest additions.

Files shared with the VirtualBox VM are owned by user "docker" and group "staff" inside the VM. Processes inside the VM (and containers) cannot change ownership of those files.

As a workaround, you can try to run your container as the same uid/gid of those files (--user 1000:50);

-u, --user=""                 Username or UID (format: <name|uid>[:<group|gid>])

--ulimit=[] Ulimit options

There's also an open issue on the GitHub issue tracker that mentions some workarounds; #581 Only root can write to OSX volumes / Can't change permissions within