What is the difference between php-cli and php-fpm, why 2 php variants and why choose one or the other?
They are different tools for different purposes:

php-cli is the standalone tool for running a PHP scripts in the same way you would run it from the command line: php somescript.php.  It seems you can also use it to base other images from.

This variant contains the PHP CLI tool with default mods. If you need a web server, this is probably not the image you are looking for. It is designed to be used both as a throw away container (mount your source code and start the container to start your app), as well as a base from which to build other images.


php-fpm is the FastCGI server implementation of PHP which you would use with a FastCGI compliant web server such as Apache or Nginx.

This variant contains PHP-FPM, which is a FastCGI implementation for PHP. See the PHP-FPM website for more information about PHP-FPM.



You also have two other variants:

php-apache which is just Apache configured with mod_php
php-alpine is the smallest possible Docker image based upon Alpine Linux, albeit with some compatibility issues.

You can see all of the Dockerfiles on GitHub and whilst it doesn't appear that php-fpm is based upon php-cli practically they are likely to be very similar and php-fpm is probably a superset of php-cli.