我正在使用以下内容开发 PHP 7.1 Web 应用程序:
运行时
docker-compose up -d
,我的绑定(bind)挂载项目目录的所有者和组更改为root。因此,每当我尝试使用 git pull
提交更改或从远程提取,我会看到以下内容:error: unable to unlink old 'gulpfile.js' (Permission denied)
fatal: Could not reset index file to revision 'HEAD^'.
Changing the project directory's owner and group回到我的用户删除错误。在使用 Docker Compose 进行开发时,是否有更简单的方法来防止这些用户权限冲突?
编辑
这是我当前目录结构的概述:
dockerComposeAndProjectDir/
|-- projectDirectory/
|-- dockerComposeDirectory/
|-- docker-compose.yml
最佳答案
如本文所述 docker (err... moby!) issue
If you
chown
the volume (on the host side) before bind-mounting it, it will work.
In that case, you could do:
mkdir /tmp/www
chown 101:101 /tmp/www
docker run -v /tmp/www:/var/www ubuntu stat -c "%U %G" /var/www
(Assuming that
101:101
is theUID:GID
of thewww-data
user in your container.)Another possibility is to do the bind-mount, then chown inside the container.
Using volumes just works assuming the image has data at the path your mounting to.
Using binds uses the host path's UID/GID.
UID/GID in the container is the same as UID/GID on the host... even if user/group names don't match, UID/GID is what matters here.
我引用了OP lolsky至
phpdocker-io/base-images/php/7.1
Dockerfile .OP得出结论:
The
php:7.1-fpm
Dockerfile indicates that thephp-fpm
service would be run aswww-data
, so I was incorrect about the container's user.
Chowning the volume after the initial bind mount seems to work.
Anytime the volume needs to be recreated by Docker Compose, I have to chown it again, which gets a little annoying, but it does solve my issue.
关于git - 错误 : unable to unlink old 'gulpfile.js' (Permission denied) while using Docker Compose for development environment,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43578095/