0

I am using official Docker Php-fpm (https://github.com/docker-library/php/blob/master/7.2/alpine3.8/fpm/Dockerfile) and official Nginx Image for my php website. I have configured Nginx to talk to php-fpm over port 9000. The entrypoint of the docker is given below.

#!/bin/sh
set -e

# first arg is `-f` or `--some-option`
if [ "${1#-}" != "$1" ]; then
    set -- php-fpm "$@"
fi

exec "$@"

You can see when we try to execute a command like docker exec -it container whoami, it is prefixed with php-fpm.

So my question is when I pass a PHP cli script like e.g docker exec -it container composer install how it is interpreted ? does composer install processed by php-fpm or php-cli (/usr/local/bin/php) ?

As per my knowledge composer is a cli script which I install like below should be processed by php-cli.

curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin -- --filename=composer
SkyRar
  • 1,107
  • 1
  • 20
  • 37
  • It will use the CLI SAPI. – Jonnix Oct 29 '18 at 13:02
  • Is Php-fpm clever enough to pass the script to CLI Sapi when it detects it as command line script otherwise pass it to CGI sapi? – SkyRar Oct 29 '18 at 13:14
  • What? Why would it? It runs where you tell it to run. If you send something to FPM it will run in FPM, it won't randomly hand over to a different SAPI. – Jonnix Oct 29 '18 at 13:30
  • Check the entrypoint please. It always prefix `php-fpm` with any command you pass e.g if you pass `composer install` it turns to something like `php-fpm composer install` . – SkyRar Oct 29 '18 at 13:45
  • `docker exec` ignores the entrypoint (script or otherwise). It’s only used on the initial `docker run`. You might consider finding a way to do whatever task is involved here without using it, though; it’s really useful for debugging but not a great idea as part of the core workflow. – David Maze Oct 29 '18 at 13:48
  • 1
    Thanks @DavidMaze . I think I got it now. So `exec "$@"` only executes the command that is passed as CMD in Dockerfile i.e here `CMD ["php-fpm"]` . Command from `docker exec` doesn't override that CMD["php-fpm"]. – SkyRar Oct 29 '18 at 14:15

1 Answers1

0

exec "$@" only executes the command that is defined as CMD in Dockerfile/Docker-compose file only once when the container is created initially. Once the container starts and you want to run any command on it then that command from docker exec doesn't override that CMD["php-fpm"]

Also composer script uses php-cli not php-fpm. https://github.com/dbjpanda/composer/blob/70557f3ab7b84a896179396509611fae66b19773/bin/composer#L4

SkyRar
  • 1,107
  • 1
  • 20
  • 37