Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add supervisor in php:7-fpm image

I use the php:7-fpm image, and I would like install and use Supervisor, to run some PHP script in background (rabbitmq workers).

I can easily install supervisor, create the conf file and add it in the image. But, I don't know how to do for launch it at the container start. If I replace que CMD with supervisor, then php-fpm don't start. At the end of the php-fpm dockerfile in the docker library, they use CMD ["php-fpm"], I've try to add it in my supervisor conf, and use CMD /usr/bin/supervisord -n -c /etc/supervisor/supervisord.conf, it start supervisor, and a simple php service. But it don't work.

Can we use many CMD ? Or are there any simple solution ?

Thanks a lot for your help.

My Dockerfile:

FROM php:7.1.5-fpm

############################
# Install PHP requirements #
############################

# Install wget, git and libraries needed by php extensions
RUN apt-get update && \
    apt-get install -y \
    zlib1g-dev \
    wget \
    git \
    supervisor

# Remove lists
RUN rm -rf /var/lib/apt/lists/*

# Compile ICU (required by intl php extension)
RUN curl -sS -o /tmp/icu.tar.gz -L http://download.icu-project.org/files/icu4c/58.2/icu4c-58_2-src.tgz && \
    tar -zxf /tmp/icu.tar.gz -C /tmp && \
    cd /tmp/icu/source && \
    ./configure --prefix=/usr/local && \
    make && \
    make install

# Configure, install and enable php extensions
RUN docker-php-ext-configure intl --with-icu-dir=/usr/local
RUN docker-php-ext-install intl pdo pdo_mysql zip bcmath
RUN docker-php-ext-enable opcache

# Install Composer
RUN php -r "readfile('https://getcomposer.org/installer');" | php -- --install-dir=/usr/local/bin --filename=composer && chmod +x /usr/local/bin/composer

# Copy the php.ini file
COPY php.ini /usr/local/etc/php/

##################
# Define workdir #
##################
WORKDIR /var/www/html/current

My docker-compose.yml:

php:
    container_name: php
    build: ./docker/php
    volumes:
        - .:/var/www/html/current:rw
        - ./docker/php/php.ini:/usr/local/etc/php/php.ini:ro
        - ./docker/php/supervisor/blast_consumer.conf:/etc/supervisor/conf.d/blast_consumer.conf:ro
    networks:
        - default

My blast_consumer:

[program:php-fpm]
command=/usr/sbin/php-fpm
numprocs=1
autostart=true
autorestart=true
stderr_logfile=/var/log/php-fpm_consumer.err.log
stdout_logfile=/var/log/php-fpm_consumer.out.log
priority=100

[program:blast_consumer]
command=/var/www/html/current/bin/console rabbitmq:consumer blast
numprocs=1
autostart=true
autorestart=true
stderr_logfile=/var/log/blast_consumer.err.log
stdout_logfile=/var/log/blast_consumer.out.log
priority=200
like image 763
mpiot Avatar asked Oct 23 '25 01:10

mpiot


1 Answers

I see that php-fpm is located at /usr/local/sbin/php-fpm. So update your supervisor command accordingly:

[program:php-fpm]
command=/usr/local/sbin/php-fpm
numprocs=1
autostart=true
autorestart=true
stderr_logfile=/var/log/php-fpm_consumer.err.log
stdout_logfile=/var/log/php-fpm_consumer.out.log
priority=100

[program:blast_consumer]
command=/var/www/html/current/bin/console rabbitmq:consumer blast
numprocs=1
autostart=true
autorestart=true
stderr_logfile=/var/log/blast_consumer.err.log
stdout_logfile=/var/log/blast_consumer.out.log
priority=200

To have further information of your supervisor, do this inside container:

supervisorctl status
supervisorctl tail php-fpm
like image 102
Robert Avatar answered Oct 25 '25 14:10

Robert



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!