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 - Unable to pull images - certificate issues?
  • docker-compose environment variables used as path for volumes don't get resolved
  • Docker build gives “unable to prepare context: context must be a directory: /Users/tempUser/git/docker/Dockerfile”
  • How is Vagrant an advantage over boot2docker? [closed]
  • What are the best practices to deploy and host artifacts for a Docker Multicontainer environment in Elasticbeanstalk for Scala Apps?
  • Docker's --memory switch does not work as expected
  • # 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..

  • how to debug container images using openshift
  • How can I send command line options to my dockerized program that I start with “docker-compose up”?
  • Docker cpu shares and garant minimum allocated CPU for container
  • How to create Dockerfile which installs Python 3 and nltk in a Ubuntu container?
  • gitlab-ci-multi-runner 9.2.0: ERROR: Job failed: exit code 252
  • Jenkins Docker Container can't access docker.sock
  • 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.