Docker php5-fpm service exited (code 0)
Read a lot of topics, but couldn’t understand what’s going on. All is working fine before I add ENTRYPOINT to my Dockerfile. Container stops immediately without demonizing php-fpm:
FROM php:5.6-fpm // ..Some installation instructions # Entrypoint script COPY ./run.sh /run.sh RUN chmod +x /run.sh ENTRYPOINT ["/run.sh"] CMD ["php-fpm"]
The content of run.sh:
# Install all dependencies php -d allow_url_fopen=on /usr/local/bin/composer install
As I understand my entrypoint will be executed with run.sh and then exited. If I will remove it then default entrypoint will be starting nginx in background. What is the best solution to run shell scripts without redefining entrypoint? Or maybe I’m talking wrong things..
3 Solutions collect form web for “Docker php5-fpm service exited (code 0)”
The problem is this:
starting nginx in background
You need a process running in the foreground. If there is none, the container will exit. I think you should keep nginx running in the foreground.
Found the way to put composer in a separate container. So i will not touch my php-fpm at all, as the best practice is one process per container.
My app container that contains all project files (composer.json, .git etc.) will provide Dockerfile:
FROM composer/composer:php5 # Set application directory WORKDIR /var/www/html ENTRYPOINT /usr/local/bin/composer install CMD ["true"]
docker-compose up -d this will bring all the dependencies from composer.json into mapped directory.
ENTRYPOINT and CMD are combined to create the final COMMAND that is run when the container is started. In your case this gives:
which means that
php-fpm acts as an argument to the
/run.sh script. That’s obviously not what you want.
You can fix this by starting php-fpm inside your script AND making sure that it runs as PID1 using
exec. Running the main process as Process ID 1 assures that it will receive SIGKILL and SIGTERM interrupts (Ctrl–C for instance) and exit gracefully if possible.
# Install all dependencies
php -d allow_url_fopen=on /usr/local/bin/composer install
Your CMD should then be empty:
Then in your container you can specify arguments to php-fpm via the command. Eg:
docker run -d my_php_fpm_image --help