这可能是之前问过的甚至是讨论过的,但是我找不到任何可以帮助我的东西。我在Windows中都运行Docker version 19.03.4, build 9013bf5
和docker-compose version 1.25.0-rc4, build 8f3c9c58
,并且都是Edge版本。我的项目Dockerfile
如下所示:
FROM php:7.2-apache
RUN apt-get update && apt-get install -y \
zlib1g-dev \
git \
unzip \
&& rm -rf /var/lib/apt/lists/ \
&& docker-php-ext-install zip pdo_mysql \
&& a2enmod rewrite \
&& pecl install xdebug-2.7.2 && docker-php-ext-enable xdebug \
&& mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini" \
&& mv /var/www/html /var/www/localproj \
&& chown -R www-data:www-data /var/www/ \
&& ln -s /usr/local/bin/php /usr/bin/php
COPY --from=composer:1.9 /usr/bin/composer /usr/bin/composer
COPY docker/apache/bootstrap.sh /usr/local/bin/docker-app-entrypoint
WORKDIR /var/www/localproj
ENTRYPOINT ["docker-app-entrypoint"]
CMD ["apache2-foreground"]
bootstrap.sh
文件就是这个文件:
#!/bin/bash
set -e
>&2 echo "Running composer install"
php -dxdebug.remote_enable=0 /usr/bin/composer install -n
>&2 echo "Composer install complete."
chown -R www-data:www-data /var/www/localproj
exec docker-php-entrypoint "$@"
每次启动容器时,都会出现以下错误:
localproj | Script php bin/console cache:clear returned with error code 1
localproj | !! [04-Nov-2019 16:27:26 UTC] PHP Warning: file_put_contents(/var/www/localproj/var/cache/local/annotations.map): failed to open stream: No such file or directory in /var/www/localproj/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php on line 377
localproj | !!
localproj | !! In Filesystem.php line 290:
localproj | !!
localproj | !! Cannot rename "/tmp/removed-ids.phpbOhMis" to "/var/www/localproj/var/cache/
localproj | !! local/Container1LP3QEI/removed-ids.php".
显然,具有权限的东西是错误的。我尝试了这种“讨厌”的解决方案(如果您知道更好的一种,请在此处添加)解决方案,但它对我也不起作用:
#!/bin/bash
set -e
mkdir /var/www/localproj/var/cache
mkdir /var/www/localproj/var/log
chmod -R 777 /var/www/localproj/var
chown -R root:root /var/www/localproj
>&2 echo "Running composer install"
php -dxdebug.remote_enable=0 /usr/bin/composer install -n
>&2 echo "Composer install complete."
chown -R www-data:www-data /var/www/localproj
exec docker-php-entrypoint "$@"
这可能是Docker Edge版本引起的吗? (我不这么认为,但值得一提)。我在这里想念的是什么?为什么权限不允许PHP复制/var/www/localproj/var
目录上的文件?