上一篇咱们写了如何用 Docker 部署 Laravel 应用,而后这一篇咱们写一下如何部署含有队列
以及任务调度
的 Laravel 应用。php
docker/app.cron
文件注意一下,文件最后的空行是必须的。html
#!/usr/bin/env bash PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin * * * * * cd /var/www/html && php artisan schedule:run >> /dev/null 2>&1
docker-entrypoint-queue.sh
注意一下,此文件须要执行权限。laravel
#!/usr/bin/env bash php artisan cache:clear php artisan config:cache php artisan route:cache php artisan view:cache # 加载调度任务并重启 cron crontab docker/app.cron /etc/init.d/cron restart # 执行队列 php artisan queue:work --timeout=60
docker compose
运行程序:./docker-compose.yml
version: "3.4" services: api: build: . image: example-laravel networks: - frontend - backend environment: - APP_ENV=development ports: - "80:80" entrypoint: ./docker-entrypoint.sh queue: build: . image: example-laravel networks: - backend environment: - APP_ENV=development entrypoint: ./docker-entrypoint-queue.sh networks: frontend: backend:
docker-compose up -d