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:

  • docker enterprise solution?
  • Difference between Docker and CS Docker Engine ?
  • docker linking how can both containers know each others ip
  • No network on host machine when running a Docker container
  • Connecting to a USB Android Device in a Docker Container via adb
  • How to deploy Spring Boot application to Google Managed VM
  • # 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..

  • Vagrant: use provider and provision togather
  • Save data generated from a Python app running in Docker swarms in Mysql Database
  • “docker run” fails with “-v” options on CentOS6.5
  • Can I use Docker like this …?
  • Dockerfile or Registry? Which is the preferred strategy for distribution?
  • elastic beanstalk can not find Dockerfile
  • 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"]
    

    After initiating 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:

    ["/run.sh", "php-fpm"]
    

    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 (CtrlC for instance) and exit gracefully if possible.

    # Install all dependencies
    php -d allow_url_fopen=on /usr/local/bin/composer install
    exec php-fpm

    Your CMD should then be empty:

    CMD []

    Then in your container you can specify arguments to php-fpm via the command. Eg:

    docker run -d my_php_fpm_image --help

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.