简体   繁体   English

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

[英]Docker (NGINX, PHP, mySQL) and Windows - File Permissions

I've been looking into docker for a few hours; 我一直在研究docker几个小时。 I'm running Windows 8.1 as the host machine, and VirtualBox with boot2docker. 我将Windows 8.1作为主机运行,并将VirtualBox与boot2docker一起运行。

This is my docker-compose.yml: 这是我的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); 这很好(我可以转到我的docker ip地址并查看nginx欢迎页面); although when I run mkdir for example (through php) it will give an error regarding windows permissions. 虽然当我运行mkdir例如(通过php)时,它将给出有关Windows权限的错误。

You should use volumes tag instead of volumes_from 您应该使用volumes的标签,而不是volumes_from

  • volumes can mount directories from host machine to container and volumes可以将目录从主机挂载到容器和
  • volumes_from mounts directories from other services or containers volumes_from从其他服务或容器挂载目录

Please look at docker-compose file documentation 请查看docker-compose文件文档

And your docker-compose file should look like this: 您的docker-compose文件应如下所示:

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. 这是使用VirtualBox来宾添加功能与VirtualBox虚拟机共享Windows文件系统的方式的限制。

Files shared with the VirtualBox VM are owned by user "docker" and group "staff" inside the VM. 与VirtualBox VM共享的文件由VM中的用户“ docker”和组“ staff”拥有。 Processes inside the VM (and containers) cannot change ownership of those files. VM(和容器)内部的进程无法更改这些文件的所有权。

As a workaround, you can try to run your container as the same uid / gid of those files ( --user 1000:50 ); 解决方法是,您可以尝试以与这些文件相同的uid / gid (-- --user 1000:50 )运行容器。

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

--ulimit=[] Ulimit options --ulimit = [] Ulimit选项

There's also an open issue on the GitHub issue tracker that mentions some workarounds; GitHub问题跟踪器上还有一个未解决的问题,其中提到了一些解决方法。 #581 Only root can write to OSX volumes / Can't change permissions within #581只有root可以写入OSX卷/不能在其中更改权限

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM