I am experimenting with Docker and want to move from a local MAMP stack to Docker. Of course I stumbled upon the official php:7.0
image but I want to use Apache as well so it seems as if php:7.0-apache
is the way to go. However I saw that there is an image called php:7.0-alpine
which is much slimmer while there are two versions for Apache as well namely httpd:2.4
and httpd:2.4-alpine
.
Is there any suggested combination to use both Apache and PHP (either separated or combined) while still having small image sizes? Furthermore I would like to know where I can review the available modules in the images since I want to use MariaDB and mod_rewrite as well which could possibly have more dependencies which have been omitted to keep the size small.
Information on implementing the desired infrastructure with nginx
I came across this very detailed and awesome tutorial on how to split up nginx and PHP as well as MySQL into different containers but attach PHP to nginx using FCGI. This implies that I can use all the different alpine-based images of the tools and link them using FCGI. Unfortunately I have never heard of or worked with FCGI but I guess some more research will yield information on how to implement this infrastructure using Apache.
Running Apache/NGINX and PHP with FCGI
If you want to run Apache and PHP in separate containers, you'll need to use a PHP-FPM container (like for example, using the
php:7-fpm
orphp:7-fpm-alpine
image) and then use FCGI to connect the two. By default, the official PHP-FPM images expose the TCP port 9000 for this, which should be sufficient for most cases.For PHP-FPM, the official PHP image should do fine (regarding size, the
7.0.14-fpm-alpine
tag is only 31M in size). Regarding Apache, I've come to like thewebdevops/apache
image (I'm not affiliated in any way). It also comes with an Alpine-based version that is only 38M in size and works well together with PHP-FPM.Here's how you start separate PHP-FPM and Apache containers, linked together using FCGI:
For using Nginx instead, simply substitute the
webdevops/apache
image withwebdevops/nginx
.Adding custom extensions
Since you've also asked about adding additional PHP extensions to your image: this is covered in the official PHP image's documentation. You can add custom PHP extensions to the PHP base image by running
docker-php-ext-install
in a custom Dockerfile:This allows you to build your custom image based on one of the PHP-FPM base images, adding all extensions that you require in the
Dockerfile
.