git - 错误 : unable to unlink old 'gulpfile.js' (Permission denied) while using Docker Compose for development environment

标签 git symfony docker permissions docker-compose

我正在使用以下内容开发 PHP 7.1 Web 应用程序:

  • Symfony 3.2
  • Docker 撰写 1.12.0
  • Ubuntu 16.04 x64

  • 运行时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 the UID:GID of the www-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 the php-fpm service would be run as www-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/

    相关文章:

    linux - 重新启动我的电脑,突然 git 不工作了

    git - 如何比较来自两个不同分支的文件

    svn - Git 与 SVN - 网络性能(用于备份)

    orm - Symfony 3 在实体中获取当前用户

    reactjs - Docker - 提供 react 应用程序,asset-manifest.json 文件名不正确

    docker - 如何从docker-compose文件中查看容器的容器健康状态

    git - 打开 pull 请求期间上游存储库发生变化? (如何)我应该 merge 到我的 fork 中?

    mysql - 水合使用学说 native 查询生成的对象,没有 ID 字段

    symfony - 简单检查 Twig 模板中的表单字段是否有错误

    ubuntu - docker run --ulimit cpu=10 超时后不会终止 java 进程