上一篇咱們寫了如何用 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