我无法刷新Laravel缓存,我认为问题可能与使用多个运行Laravel堆栈的Docker容器有关。我已经尝试过php artisan cache:clear
和php artisan config:cache
。我已经删除了bootstrap/cache/config.php
,但该文件只是以旧配置重新出现,就像一些不死生物在困扰着我。
我能够刷新缓存的唯一方法是使用docker-compose down
完全删除容器,然后再次运行容器。
在下面的docker-compose中,您可以看到我的应用程序,队列和调度程序容器都运行Laravel堆栈,并从主机安装了代码库。这会导致问题吗?
docker-compose.yml
version: '3'
services:
#PHP Service
app:
build:
context: .
dockerfile: Dockerfile
image: digitalocean.com/php
container_name: app
restart: unless-stopped
tty: true
env_file: '.env'
environment:
SERVICE_NAME: app
SERVICE_TAGS: dev
#APP_ENV: local
working_dir: /var/www
volumes:
- ./:/var/www
- ./php/local.ini:/usr/local/etc/php/conf.d/local.ini
- ./php/opcache.ini:/usr/local/etc/php/conf.d/opcache.ini
networks:
- app-network
scheduler:
image: digitalocean.com/php
container_name: scheduler
restart: unless-stopped
depends_on:
- app
volumes:
- .:/var/www
env_file: '.env'
environment:
CONTAINER_ROLE: scheduler
networks:
- app-network
queue:
image: digitalocean.com/php
container_name: queue
restart: unless-stopped
depends_on:
- app
volumes:
- .:/var/www
- ./supervisor/supervisord.conf:/etc/supervisor/supervisord.conf
- ./supervisor/conf.d:/etc/supervisor/conf.d
env_file: '.env'
environment:
CONTAINER_ROLE: queue
networks:
- app-network
#Nginx Service
webserver:
image: nginx:alpine
container_name: webserver
restart: unless-stopped
tty: true
ports:
- "${local_ip}:${host_web_port}:80"
#- "${local_ip}:443:443"
volumes:
- ./:/var/www
- ./nginx/conf.d/:/etc/nginx/conf.d/
networks:
- app-network
#MySQL Service
db:
image: mysql:5.7.26
container_name: db
restart: unless-stopped
tty: true
ports:
- "${local_ip}:${host_db_port}:3306"
environment:
MYSQL_DATABASE: dbname
MYSQL_USER: laravel
MYSQL_PASSWORD: password
MYSQL_ROOT_PASSWORD: root_password
SERVICE_TAGS: dev
SERVICE_NAME: mysql
volumes:
- dbdata:/var/lib/mysql/
- ./mysql/my.cnf:/etc/mysql/my.cnf
networks:
- app-network
#Docker Networks
networks:
app-network:
driver: bridge
#Volumes
volumes:
dbdata:
driver: local
有人可以告诉我如何在不破坏容器的情况下重新加载缓存吗?
为了完整起见,我使用以下指南设置了Docker环境:https://www.digitalocean.com/community/tutorials/how-to-set-up-laravel-nginx-and-mysql-with-docker-compose
我正在使用以下指南运行队列和调度程序容器:https://laravel-news.com/laravel-scheduler-queue-docker。但是,我已经修改了队列以运行Supervisor。
start.sh
#!/usr/bin/env bash
set -e
role=${CONTAINER_ROLE:-app}
env=${APP_ENV:-production}
if [ "$env" != "local" ]; then
echo "Caching configuration..."
(php artisan config:cache && php artisan view:cache) # && php artisan route:cache - can't cache route closures
fi
if [ "$role" = "app" ]; then
exec php-fpm
elif [ "$role" = "queue" ]; then
echo "Running the queue..."
/usr/bin/supervisord
elif [ "$role" = "scheduler" ]; then
while [ true ]
do
php artisan schedule:run --verbose --no-interaction &
sleep 60
done
else
echo "Could not match the container role \"$role\""
exit 1
fi
答案 0 :(得分:0)
我思考现在,我了解发生了什么事。我的Laravel配置选项由.env
文件定义,我的docker-compose.yml
文件也正在读取该文件来设置容器环境变量。这些container environment variables cannot be changed at runtime总是优先于容器运行时对.env
文件所做的更改。
停止和启动容器不会更改环境变量。只有破坏容器并使其重新启动,然后重新读取.env
文件以设置环境变量,我的更改才会生效。
那么正确的设置应该是仅将.env
用于Laravel,并将一个单独的文件用于容器环境变量。换句话说,更改env_file: '.env'
中的docker-compose.yml
条目。