本文介绍了在Docker环境中运行Symfony时的文件夹权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在OSX上运行Docker容器。容器包括:


  1. Symfony

  2. Nginx

  3. php-fpm

  4. Redis

这是一个非常常见的运行Symfony应用程序的设置。



我遇到了一些奇怪的文件夹权限问题,我收到这个错误:



我的Symfony可以创建一个文件夹

  / var / www / var / chache 

但是它不能写入它。
创建缓存文件夹后,文件夹权限设置为:

  10344 drwxr-xr-x 1 1000名员工68 4月15日00:33缓存

该文件夹的所有者是我的本地OSX用户,Docker正在运行。
我已经尝试从Docker的Symfony的CLI更改文件夹权限或所有者,它没有任何效果。
我试图在我的本地控制台下面的 chmod -R 777 权限被更改,但是Symfony在缓存文件夹中创建文件夹,不能再写入它。



我还尝试在app_dev.php中禁用缓存:

  $ kernel = new AppKernel('dev',true); 
// $ kernel-> loadClassCache();
$ request = Request :: createFromGlobals();

而在config.yml中:

  twig:
cache:false

没有任何效果,所以我在这里迷路了



任何想法如何解决问题?

解决方案

没有显示你的Dockerfile,因为这样我可以给你一个容器的示例,PHP-FPM这个问题是修复的:



这一行是修复权限错误: usermod -u 1000 www-data

  FROM debian:jessie 
RUN apt-get update
运行apt-get install -y curl \
mcrypt \
&&& apt-get install -y php5 \
php5-fpm \
php5-cli \
php-pear \
php5-common \
php5 -igbinary \
php5-json \
php5-mysql \
php5-mysqlnd \
php5-gd \
php5-curl \
php5-dev \
php5-sqlite \
php5-memcached \
php5-memcache \
&& usermod -u 1000 www-data

EXPOSE 9000


I am running a Docker containers on OSX. Containers consist of:

  1. Symfony
  2. Nginx
  3. php-fpm
  4. Redis

This is a pretty common setup to run Symfony apps.

I am running into some weird folder permission issues and I'm getting this error: error screenshot

My Symfony can create a folder

/var/www/var/chache 

but then it can't write into it. Once cache folder created, folder permissions are set to this:

10344 drwxr-xr-x 1 1000 staff    68 Apr 15 00:33 cache

Owner of the folder is my local OSX user, which Docker is running under.I've tried to change folder permissions or owner from Symfony's CLI in Docker and it has no effect. I tried to chmod -R 777 under my local console, permissions are changed, but then Symfony creates folder inside cache folder and can't write into it again.

I've also tried to disable caching in app_dev.php:

$kernel = new AppKernel('dev', true); 
// $kernel->loadClassCache();
$request = Request::createFromGlobals();

And in config.yml:

twig:
    cache:        false

Nothing had effect, so I'm lost here.

Any ideas how to solve an issue?

解决方案

You have not shown you Dockerfile, because of that I can give you an example of container with PHP-FPM where this problem is fixed:

This row is fixing permission error: usermod -u 1000 www-data

FROM debian:jessie  
RUN apt-get update
RUN apt-get install -y curl \
                       mcrypt \
    && apt-get install -y php5 \
                       php5-fpm \
                       php5-cli \
                       php-pear \
                       php5-common \
                       php5-igbinary \
                       php5-json \
                       php5-mysql \
                       php5-mysqlnd \
                       php5-gd \
                       php5-curl \
                       php5-dev \
                       php5-sqlite \
                       php5-memcached \
                       php5-memcache \
    && usermod -u 1000 www-data

EXPOSE 9000

这篇关于在Docker环境中运行Symfony时的文件夹权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 00:36