G
G
glebvvs2020-10-27 16:18:34
PHP
glebvvs, 2020-10-27 16:18:34

Why does php-fpm container crash when supervisor starts?

There is such file docker-compose.yml

version: "2"
services:
  nginx:
    image: nginx:latest
    container_name: dev-chellange-nginx
    ports:
      - 7000:80
    volumes: 
      - ./docker/nginx:/etc/nginx/conf.d
      - ./src:/usr/share/nginx/html
    links:
      - php
  php:
    build: ./docker/php
    container_name: dev-chellange-php
    volumes: 
      - ./src:/var/www/html
      - ./docker/php/supervisor:/etc/supervisor/conf.d
    links:
      - mysql
      - redis
  mysql:
    image: mysql
    container_name: dev-chellange-mysql
    command: --default-authentication-plugin=mysql_native_password
    environment:
      MYSQL_ROOT_PASSWORD: password
      MYSQL_DATABASE: dev_chellange
  redis:
    image: redis
    container_name: dev-chellange-redis


PHP container dockerfile
FROM php:7.4-fpm

# Install dependencies
RUN apt-get update && apt-get install -y \
    build-essential \
    supervisor \
    libpng-dev \
    libjpeg62-turbo-dev \
    libfreetype6-dev \
    locales \
    zip \
    jpegoptim optipng pngquant gifsicle \
    vim \
    unzip \
    git \
    curl

# Install extensions
RUN docker-php-ext-install pdo pdo_mysql && docker-php-ext-enable pdo_mysql
RUN pecl install redis && docker-php-ext-enable redis

CMD ["/usr/bin/supervisord"]


Worker supervisor configuration:
[program:queue-workers]
process_name=%(program_name)s_%(process_num)02d
command=php /var/www/html/application/artisan queue:work --sleep=3 --tries=3 --max-time=3600
autostart=true
autorestart=true
user=root
numprocs=5
redirect_stderr=true
stdout_logfile=/etc/supervisor/conf.d/queue-workers.log
stopwaitsecs=3600


The problem is the following. If you start the supervisor directly through the container terminal after doing docker-compose up , then everything works, the supervisor starts and the worker works correctly. But if you try to do this through the cmd directive in the dockerfile (as indicated in the example), then the container crashes after the docker-compose up command .

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question