【问题标题】:how to set permissions to cache and log symfony docker container如何设置权限以缓存和记录 symfony docker 容器
【发布时间】:2019-03-28 16:18:29
【问题描述】:

我的 Symfony 应用程序有一个 Dockerfile,但容器没有缓存和日志目录的写入权限。

我尝试使用 Symfony 文档获取权限,但它不起作用。我已经将容器用户设置为root,但问题还是一样。

这是我的Dockerfile

FROM trafex/alpine-nginx-php7:ba1dd422

RUN apk --update add git php7-sockets php7-bcmath php7-pdo_mysql php7-pdo && rm /var/cache/apk/* \
    && curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

COPY ./docker/nginx/nginx.conf /etc/nginx/nginx.conf

COPY . /var/www/html

RUN composer install \
     --ignore-platform-reqs \
        --no-interaction \
        --no-plugins \
        --no-scripts \
        --prefer-dist

EXPOSE 8080

如何设置正确的权限来运行它?

【问题讨论】:

    标签: php symfony docker nginx


    【解决方案1】:

    从 docker 映像的 Dockerfile 看来,运行 NGINX 和 PHP-FPM 的用户似乎是 nobody

    因此,您应该能够为该用户授予对这些文件的权限来完成所有工作

    FROM trafex/alpine-nginx-php7:ba1dd422
    
    RUN apk --update add git php7-sockets php7-bcmath php7-pdo_mysql php7-pdo && rm /var/cache/apk/* \
        && curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
    
    COPY ./docker/nginx/nginx.conf /etc/nginx/nginx.conf
    
    COPY . /var/www/html
    RUN chown -R nobody:nobody /var/www/html
    
    RUN composer install \
         --ignore-platform-reqs \
            --no-interaction \
            --no-plugins \
            --no-scripts \
            --prefer-dist
    
    EXPOSE 8080
    

    但更好的是,你应该使用与they use in the original image相同的语法

    FROM trafex/alpine-nginx-php7:ba1dd422
    
    RUN apk --update add git php7-sockets php7-bcmath php7-pdo_mysql php7-pdo && rm /var/cache/apk/* \
        && curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
    
    COPY ./docker/nginx/nginx.conf /etc/nginx/nginx.conf
    
    COPY --chown=nobody . /var/www/html
    
    RUN composer install \
         --ignore-platform-reqs \
            --no-interaction \
            --no-plugins \
            --no-scripts \
            --prefer-dist
    
    EXPOSE 8080
    

    【讨论】:

      猜你喜欢
      • 2016-05-09
      • 2016-04-29
      • 2016-12-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-07
      相关资源
      最近更新 更多