Skip to content

Docker PHP base image on which you add layers and create a final image containing your App.

Notifications You must be signed in to change notification settings

ems-project/base-php-docker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Base Docker image Docker Build

Docker base image is the basic image on which you add layers (which are basically filesystem changes) and create a final image containing your App.

Features

Use Official PHP Docker image as parent.
Use Supervisor as manager for Webserver and PHP-FPM. Supervisord is therefore process 1.
Run container as non-privileged.
Container Entrypoint hooks available.

Build

Prerequisite

You must install make, m4.

Generate Dockerfile

make Dockefile

Build locally Docker images

make build[-fpm|-apache|-nginx|-cli|-all][-dev] [ PHP_VERSION=<PHP Version you want to build> ] \
                                                [ DOCKER_IMAGE_NAME=<PHP Docker Image Name you want to build> ] \
                                                [ NODE_VERSION=<NodeJS Version> ] \
                                                [ COMPOSER_VERSION=<Composer Version> ] \
                                                [ AWS_CLI_VERSION=<AWS CLI Version> ] \
                                                [ PHP_EXT_REDIS_VERSION=<PHP Extension Redis Version> ] \
                                                [ PHP_EXT_APCU_VERSION=<PHP Extension APCu Version> ] \
                                                [ PHP_EXT_XDEBUG_VERSION=<PHP Extension XDebug Version> ]

Default value of Docker build arguments is grabbed from the .build.env file if it is present, otherwise Docker build will use the default values available in the Dockerfile. Default values can be also overridden via the make command line.

Example building fpm variant prd Docker image

make build-fpm PHP_VERSION=8.1.28

Provide docker image : docker.io/elasticms/base-php:8.1.28-fpm-prd

make build-fpm PHP_VERSION=8.1.28 DOCKER_IMAGE_NAME=docker.io/lambdauser/mybasephpimage

Provide docker image : docker.io/lambdauser/mybasephpimage:8.1.28-fpm-prd

Example building fpm variant dev Docker image

make build-fpm-dev PHP_VERSION=8.1.28

Provide docker image : docker.io/elasticms/base-php:8.1.28-fpm-dev

Example building nginx variant dev Docker image

make build-nginx-dev PHP_VERSION=8.1.28

Provide docker image : docker.io/elasticms/base-php:8.1.28-nginx-dev

Example building all variants Docker image

make build-all PHP_VERSION=8.1.28

Provide docker images :

  • docker.io/elasticms/base-php:8.1.28-fpm-prd
  • docker.io/elasticms/base-php:8.1.28-fpm-dev
  • docker.io/elasticms/base-php:8.1.28-apache-prd
  • docker.io/elasticms/base-php:8.1.28-apache-dev
  • docker.io/elasticms/base-php:8.1.28-nginx-prd
  • docker.io/elasticms/base-php:8.1.28-nginx-dev
  • docker.io/elasticms/base-php:8.1.28-cli-prd
  • docker.io/elasticms/base-php:8.1.28-cli-dev

Test

Prerequisite

You must install bats, docker, docker-compose and create a local network called docker_default.

Test Docker images builded locally

make test[-fpm|-apache|-nginx|-cli|-all][-dev] PHP_VERSION=<PHP Version you want to test>

Example testing of prd builded docker image

make test PHP_VERSION=8.1.28

Example testing of dev builded docker image

make test-dev PHP_VERSION=8.1.28

Releases

Releases are done via GitHub actions and uploaded on Docker Hub.

Supported tags and respective Dockerfile links

Image Variants

The docker.io/elasticms/base-php images come in many flavors, each designed for a specific use case.

docker.io/elasticms/base-php:<version>-fpm[-prd]

This image is based and use the official PHP Docker Hub image docker.io/php:8.1.x-fpm-alpine3.19 as parent.
It is configured and configurable to support any PHP application.
It use the default php.ini-production configuration files and Supervisor to help automate the Docker image.

docker.io/elasticms/base-php:<version>-dev

This image use base-php:<version>-fpm-prd (see above) as parent layer.
It use the default php.ini-development configuration files.
It is strongly recommended to not use this image in production environments!

In addition to the parent layer, this variant include install :

docker.io/elasticms/base-php:<version>-apache[-prd]

This image use base-php:<version>-fpm-prd (see above) as parent layer.
This variant contains Apache httpd in conjunction with PHP-FPM and uses supervisor as manager for Apache and PHP-FPM.

docker.io/elasticms/base-php:<version>-nginx[-prd]

This image use base-php:<version>-fpm-prd (see above) as parent layer.
This variant contains Nginx Webserver in conjunction with PHP-FPM and uses supervisor as manager for Nginx and PHP-FPM.

docker.io/elasticms/base-php:<version>-cli[-prd]

This variant contains the PHP CLI tool with default mods. In addition we install and configure :

docker.io/elasticms/base-php:<version>-apache-dev

This image use base-php:<version>-fpm-dev (see above) as parent layer.
This variant contains Apache Webserver in conjunction with PHP-FPM and uses supervisor as manager for Apache and PHP-FPM.
It is strongly recommended to not use this image in production environments!

docker.io/elasticms/base-php:<version>-nginx-dev

This image use base-php:<version>-fpm-dev (see above) as parent layer.
This variant contains Nginx Webserver in conjunction with PHP-FPM and uses supervisor as manager for Nginx and PHP-FPM.
It is strongly recommended to not use this image in production environments!

docker.io/elasticms/base-php:<version>-cli-dev

This image use base-php:<version>-cli-prd (see above) as parent layer.

In addition to the parent layer, this variant include install :

Warning : The following images are deprecated and are no longer maintained.

They will be removed soon, please update your dockerfiles and docker-compose.yml files ...

Deprecated Image Name Replaced Image Name
docker.io/elasticms/base-php-fpm:<version> docker.io/elasticms/base-php:<version>-fpm[-prd]
docker.io/elasticms/base-php-dev:<version> docker.io/elasticms/base-php:<version>-fpm-dev
docker.io/elasticms/base-apache-fpm:<version> docker.io/elasticms/base-php:<version>-apache[-prd]
docker.io/elasticms/base-apache-dev:<version> docker.io/elasticms/base-php:<version>-apache-dev
docker.io/elasticms/base-nginx-fpm:<version> docker.io/elasticms/base-php:<version>-nginx[-prd]
docker.io/elasticms/base-nginx-dev:<version> docker.io/elasticms/base-php:<version>-nginx-dev
docker.io/elasticms/base-php-cli:<version> docker.io/elasticms/base-php:<version>-cli[-prd]
docker.io/elasticms/base-php-cli-dev:<version> docker.io/elasticms/base-php:<version>-cli-dev

Update (21/06/2023) - Starting from version v8.1.20, the images mentioned above are no longer being updated or supported.

PHP-FPM Configuration

You can change the amount of memory that PHP-FPM can use by changing / passing the environment variables PHP_FPM_MAX_CHILDREN and PHP_FPM_REQUEST_MAX_MEMORY_IN_MEGABYTES.
These values can be overridden automatically by the startup script if a QoS memory limit is applied and detected in your container.
However, this value can be reduced to a percentage by the configuration of the environment variable CONTAINER_HEAP_PERCENT (default: 80 %).

Name Default Value Description
PHP_FPM_MAX_CHILDREN_AUTO_RESIZING true Enable auto-resizing of PHP-FPM Pool Memory settings based on container size.
PHP_FPM_MAX_CHILDREN 40 The maximum number of child processes to be created. (doc)
PHP_FPM_REQUEST_MAX_MEMORY_IN_MEGABYTES 16 The maximum amount of memory in MB that a script is allowed to allocate. (doc)
CONTAINER_HEAP_PERCENT 0.80 Percentage of total memory allowed to use by PHP-FPM.

Varnish Configuration

Name Default Value Description
VARNISH_ENABLED false Enable Varnish. Listen on 6081 for HTTP proto when Varnish is enabled. Management interface is available on 6082.
VARNISH_STORAGE_MALLOC_CUSTOM_SIZE 200M Malloc is a memory based backend. Each object will be allocated from memory. If your system runs low on memory swap will be used. (doc)
VARNISH_NCSA_LOG_FORMAT_CUSTOM %%h %%l %%u %%t %%D \"%%r\" %%s %%b %%{Varnish:hitmiss}x \"%%{User-agent}i\" The varnishncsa utility reads varnishd(1) shared memory logs and presents them in the Apache / NCSA “combined” log format. (doc)
VARNISH_TTL_CUSTOM 120 Specifies the default time to live (TTL) for cached objects. This is a shortcut for specifying the default_ttl run-time parameter. (doc)
VARNISH_MIN_THREADS_CUSTOM 5 The minimum number of worker threads in each pool. (doc)
VARNISH_MAX_THREADS_CUSTOM 1000 The maximum number of worker threads in each pool. (doc)
VARNISH_THREAD_TIMEOUT_CUSTOM 120 Thread idle threshold. (doc)
VARNISH_VCL_CONF_CUSTOM /etc/varnish/default.vcl Use the specified file location as VCL configuration instead of the builtin default. You must provide this file or generate it at container startup. (doc)

About

Docker PHP base image on which you add layers and create a final image containing your App.

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •