Skip to content
Advertisement

Docker Centos with php fails to start

I am trying to build a centos server with php on it I am using centos:7 image and in it install php dependencies. But that doesn’t seem to work as every time, the build is successful but just after that the container shuts down.

Here is my docker-compose.yml

version: "3.7"

services:
  server:
    build:
      context: ./.docker
    volumes:
      - ./src/:/opt/app-root/src
    ports:
      - "9000:9000"

networks:
  default:
    external:
      name: network_rp

And the Dockerfile (found in .docker/Dokerfile):

FROM centos:7

# Ajout des repo utiles
RUN rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm 
    && rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm 
    && rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm


# Installation des packages
RUN yum-config-manager --enable remi-php73 
    && yum install -y git zip unzip 
    php php-intl php-opcache php-mbstring php-dom 
    php-pdo php-mysqlnd php-pecl-xdebug php-soap 
    php-bcmath php-zip php-ast php-fpm

RUN yum update -y


# Parametrage PHP
RUN echo 'date.timezone=Europe/Paris' > /etc/php.d/00-docker-php-date-timezone.ini


# Installation composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin --filename=composer

# xdebug.ini. Activer les directives selon les besoins
RUN echo 'xdebug.remote_enable=1' >> /etc/php.d/15-xdebug.ini 
    && echo 'xdebug.remote_connect_back=0' >> /etc/php.d/15-xdebug.ini 
    && echo "xdebug.remote_host=127.0.0.1" >> /etc/php.d/15-xdebug.ini 
    && echo 'xdebug.remote_autostart=1' >> /etc/php.d/15-xdebug.ini 
    && echo 'xdebug.remote_log=/opt/app-root/src/var/logs/xdebug.log' >> /etc/php.d/15-xdebug.ini



# Vide le dossier temporaire
RUN rm -rf /tmp/*

WORKDIR /opt/app-root/src

CMD ["php-fpm"]

EXPOSE 9000

Any ideas ?

Advertisement

Answer

There are 2 problems here:

1. /var/run/php-fpm/ was missing, then you will encountered next error:

[18-Mar-2021 06:12:09] ERROR: Unable to create the PID file (/run/php-fpm/php-fpm.pid).: No such file or directory (2)
[18-Mar-2021 06:12:09] ERROR: FPM initialization failed

So, you need add next line before CMD ["php-fpm"]:

RUN mkdir -p /var/run/php-fpm

2. You need make php-fpm run in foreground, using next, see example here:

CMD [ "php-fpm", "-F" ]
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement