Public Repository

Last pushed: 2 years ago
Short Description
Alpine image with php-fpm
Full Description

Tags & Dockerfile

What is PHP-FPM?

PHP-FPM (FastCGI Process Manager) is an alternative FastCGI implementation for PHP, bundled with the official PHP distribution since version 5.3.3. When compared to the older FastCGI implementation, it contains some additional features, mostly useful for heavily loaded web servers.


PHP is installed under /php

/php # tree -d
/ # tree -d -L 1 /php/
├── bin
├── conf.d
├── etc
├── include
├── lib
├── log
├── php
├── sbin
└── var

9 directories


This container will be used along with jfusterm/nginx to serve PHP applications.

Nginx + PHP-FPM

In this scenario we will have one container with Nginx and another one with PHP-FPM.

We have to use the environmental variable PHPFPM to pass the PHP-FPM service detail using the format IP:PORT

$ docker run -d --name phpfpm01 -v /dir/php-code:/nginx/html -v /php -p 9000:9000 jfusterm/php-fp
$ docker run -d --name nginx -p 80:80 -v /dir/php-code:/nginx/html --link phpfpm01 -e PHPFPM=phpfpm01:9000 jfusterm/nginx

Nginx + Multiple PHP-FPM

In this scenario we will have one container with Nginx and multiple PHP-FPM containers serving the application. In this case Nginx will act not only as a web server but as a load balancer for the PHP-FPM pool.

$ docker run -d --name phpfpm01 -v /dir/php-code:/nginx/html -p 9001:9000 jfusterm/php-fpm
$ docker run -d --name phpfpm02 -v /dir/php-code:/nginx/html -p 9002:9000 jfusterm/php-fpm
$ docker run -d --name phpfpm03 -v /dir/php-code:/nginx/html -p 9003:9000 jfusterm/php-fpm

Once launched the PHP-FPM containers we can connect to them using their private IP or using the host IP.

Connect using the container IP

First we will get each IP.

$ docker inspect --format '{{ .NetworkSettings.IPAddress }}' phpfpm01
$ docker inspect --format '{{ .NetworkSettings.IPAddress }}' phpfpm02
$ docker inspect --format '{{ .NetworkSettings.IPAddress }}' phpfpm03

Since we connect directly to the containers, we can use the port 9000 directly.

$ docker run -d --name nginx -p 80:80 -v /dir/php-code:/nginx/html -e PHPFPM=,, jfusterm/nginx

Connect using the host IP

In this case we will use the host IP and its redirected ports.

$ docker run -d --name nginx -p 80:80 -v /dir/php-code:/nginx/html -e PHPFPM=HOST_IP:9001,HOST_IP:9002,HOST_IP:9003 jfusterm/nginx

Obviously we can connect to another PHP-FPM container no matter what their server location is.

Docker Pull Command