开发时如何在 docker 上设置文件和目录权限

how to set file and dir permissions on docker when developing

我正在使用 docker 开发一个 symfony 应用程序。 我正在共享一个主机卷,它应该包含我的项目,该项目应该 运行 与 apache。

docker run -d -ti --name web -p 80:80 -v /Users/Matteo/Documents/em3:/var/www/html/applications  ubuntu /bin/bash

我使用 ubuntu 作为基础映像,在其上安装了 apache 和 PHP7。一切正常,但是当我进入 docker:

docker exec -it web /bin/bash

root@85a23559d01b:/var/www/html/applications/auth# app/console cache:clear --env=dev


  [Symfony\Component\Filesystem\Exception\IOException]
  Failed to remove directory "/var/www/html/applications/auth/app/cache/de~/jms_serializer": .

这可能是因为目录权限?:

root@85a23559d01b:/var/www/html/applications/auth/app# ls -al | grep cache

drwxr-xr-x 1 1000 staff   374 Oct 30 21:50 cache

chmod 虽然没有任何改变:

root@85a23559d01b:/var/www/html/applications/auth/app# chmod g+w cache

root@85a23559d01b:/var/www/html/applications/auth/app# ls -al | grep cache
drwxr-xr-x 1 1000 staff   374 Oct 30 21:50 cache

我想我漏掉了什么。任何帮助将不胜感激

正如 symfony issue 2600

中的评论

you can "easily" reproduce this if you use a Linux VirtualBox on a Windows host.

[这里可能就是这种情况,使用 Docker Toolbox, instead of Docker for Windows 中的 boot2docker 及其 Hyper-V]

cache:clear is never able to remove app/cache/dev_old - but that may be an issue with the shared folder system provided by VirtualBox (read about similar issues on their forums).

You have to upgrade VirtualBox Guest Additions

OP Bertuz points out to "Changing boot2docker to use NFS for local mounts in OS X" and its file-nfs-mount-boot2docker-sh gist (and a more recent one).