symfony无法在docker上创建缓存目录

时间:2019-03-19 00:43:38

标签: php symfony docker caching

我为我的symfony应用程序创建了一个docker-compose,它可以工作,但是当该应用程序尝试创建缓存目录时,它向我抛出了权限错误:

这是我的docker-compose文件:

nginx:
      image: nginx:1.15-alpine
      restart: unless-stopped
      ports:
        - "8000:80"
      volumes:
        - .:/app:delegated
        - ./docker/nginx/nginx.conf:/etc/nginx/conf.d/default.conf:ro
      depends_on:
        - php

    php:
      build:
        context: .
        dockerfile: docker/php-fpm/Dockerfile
      restart: unless-stopped
      ports:
        - "9030:9001"
      volumes:
        - .:/app:delegated

这是我的php dockerfile:

FROM composer:1.8 AS vendor

COPY composer.json composer.lock /app/

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

FROM php:7-fpm-alpine3.8
WORKDIR /app
RUN docker-php-ext-install sockets mysqli mbstring bcmath pdo_mysql pdo
COPY . /var/www/html/app
COPY --from=vendor ./app/vendor/ /var/www/html/app/vendor/
COPY ./docker/php-fpm/php-ini-overrides.ini /etc/php/7.0/fpm/conf.d/99-overrides.ini

EXPOSE 80

当我输入localhost:8000时,这会引发我这个错误

Fatal error: Uncaught RuntimeException: Unable to create the cache directory (/app/app/cache/prod) in /app/app/bootstrap.php.cache:2725 Stack trace: #0 /app/app/bootstrap.php.cache(2686): Symfony\Component\HttpKernel\Kernel->buildContainer() #1 /app/app/bootstrap.php.cache(2465): Symfony\Component\HttpKernel\Kernel->initializeContainer() #2 /app/app/AppKernel.php(19): Symfony\Component\HttpKernel\Kernel->boot() #3 /app/app/bootstrap.php.cache(2496): AppKernel->boot() #4 /app/web/app.php(28): Symfony\Component\HttpKernel\Kernel->handle(Object(Symfony\Component\HttpFoundation\Request)) #5 {main} thrown in /app/app/bootstrap.php.cache on line 2725

我该如何解决?

1 个答案:

答案 0 :(得分:0)

负责创建缓存目录的用户没有权限。

您可以尝试将其添加到Dockerfile

RUN setfacl -R -m u:www-data:rwX -m u:`whoami`:rwX ./app/cache ./app/logs
RUN setfacl -dR -m u:www-data:rwX -m u:`whoami`:rwX ./app/cache ./app/logs

如果您是Linux用户,也可以在主机上运行它:

sudo chown www-data:www-data -R app/cache/ app/logs/