首页 > 解决方案 > 如何使用 Laravel 队列记录标准输出和标准错误:在 docker 容器内工作

问题描述

我的 docker-compose.yml

  &app-service app: &app-service-template
    container_name: k4fntr_app
    build:
      context: ./docker/php-fpm
      args:
        UID: ${UID?Use your user ID}
        GID: ${GID?Use your group ID}
    user: "${UID}:${GID}"
    hostname: *app-service
    volumes:
      - /etc/passwd/:/etc/passwd:ro
      - /etc/group/:/etc/group:ro
      - ./:/var/www/k4fntr
    environment:
      FPM_PORT: &php-fpm-port 9000
      FPM_USER: "${UID:-1000}"
      FPM_GROUP: "${GID:-1000}"
    command: ./docker/php-fpm/sh/keep-alive.sh
    depends_on:
      - redis
      - database
    networks:
      - backend-network

  &queue-service queue:
    <<: *app-service-template
    container_name: k4fntr_queue
    restart: always
    hostname: *queue-service
    command: php artisan queue:work --sleep=3 --tries=3

队列工作者运行良好,但存在一个问题。我没有将我的标准输出和标准错误记录到文件中。

在使用 docker 之前,我有一个主管实例

[program:fntr-worker]
command=php /k4fntr/artisan queue:work --sleep=3 --tries=3
autostart=true
autorestart=true
user=apache
startretries=9999999
numprocs=1
stdout_logfile=/k4fntr/storage/logs/fntr-worker.stdout.log
stderr_logfile=/k4fntr/storage/logs/fntr-worker.stderr.log

并且可以看到我的工作日志

[2019-12-06 10:47:46][grpE4prmKGTyW7Qgj2XI8WhMGv0jOa8r] Processing: App\Events\MatchOfDayOnlinePoint
[2019-12-06 10:47:46][grpE4prmKGTyW7Qgj2XI8WhMGv0jOa8r] Processed:  App\Events\MatchOfDayOnlinePoint
[2019-12-06 10:48:01][k5sMBerEzKSa2UJ3isFwUywIMOtgfsRs] Processing: App\Jobs\RatioJob
[2019-12-06 10:48:07][k5sMBerEzKSa2UJ3isFwUywIMOtgfsRs] Processed:  App\Jobs\RatioJob

我试着用

command: nohup php artisan queue:work --sleep=3 --tries=3 > app/storage/logs/laravel.log 2&>1

但我的容器因错误而失败

标签: laraveldockerdocker-composelaravel-queue

解决方案


这可能是解决方案 stdout_logfile=./k4fntr/storage/logs/fntr-worker.stdout.log


推荐阅读