wayofdev/docker-php-base
Foundational Docker PHP images with essential extensions. Multi-arch AMD64/ARM64 Alpine-based builds for CLI, FPM, and Supervisord. Optimized for production and development environments.
Docker Image: PHP Base
The docker-php-base project is a system for creating and maintaining PHP Docker images.
It uses Ansible to generate Dockerfiles for multiple PHP versions (7.4, 8.0, 8.1, 8.2, 8.3, 8.4) and types (CLI, FPM, Supervisord) on Alpine Linux.
The project automates the build process using GitHub Actions, creating multi-architecture images (AMD64 and ARM64) that are tested with goss.
Images come pre-configured with a wide array of PHP extensions and are designed to serve as a base for PHP applications in both development and production environments.
If you like/use this package, please consider โญ๏ธ starring it. Thanks!
๐ Features
- Multiple PHP Versions: Supports PHP 7.4, 8.0, 8.1, 8.2, 8.3 and 8.4.
- Various PHP Types: Includes CLI, FPM, and Supervisord configurations.
- Alpine-based: Lightweight images built on Alpine Linux.
- Pre-configured Extensions: Comes with a wide range of pre-installed PHP extensions.
- Customizable Settings: Easily adjustable PHP and OPcache settings.
- Multi-architecture Support: Built for both AMD64 and ARM64 architectures.
- Automated Builds: Utilizes GitHub Actions for continuous integration and delivery.
- Comprehensive Testing: Implements dgoss for thorough Docker image testing.
- Ansible-based Generation: Leverages Ansible for flexible and maintainable Dockerfile generation.
- Security Focused: Includes Docker Scout scans for vulnerability checks.
๐ Technology Stack
- Ansible: For generating Dockerfiles and configurations.
- Docker: Base technology for containerization.
- GitHub Actions: CI/CD pipeline for automated building, testing, and publishing.
- dgoss: For Docker image testing.
- Alpine Linux: Base OS for the Docker images.
- PHP: Core language with multiple versions (7.4, 8.0, 8.1, 8.2, 8.3, 8.4).
๐ฆ Pre-installed PHP Extensions
The images come with a variety of pre-installed PHP extensions:
| Extension | Description | Type |
|---|---|---|
| intl | Internationalization functions | native |
| pcntl | Process control | native |
| sockets | Socket communication functions | native |
| pdo_pgsql | PostgreSQL functions | native |
| pdo_mysql | MySQL functions | native |
| opcache | Improves PHP performance by storing precompiled script bytecode in shared memory | native |
| zip | Read/write functions for ZIP archives | native |
| bcmath | For arbitrary precision mathematics | native |
| exif | Exchangeable image information | native |
| gd | Image processing and manipulation library | native |
| redis | Functions for interfacing with Redis | pecl |
| memcached | Functions for interfacing with Memcached | pecl |
| decimal | Arbitrary precision floating-point decimal | pecl |
| amqp | Advanced Message Queuing Protocol (AMQP) library | pecl |
| yaml | YAML library | pecl |
| grpc | gRPC library | pecl |
| protobuf | Protocol Buffers library | pecl |
๐ Usage
The PHP base images are available on both Docker Hub and GitHub Container Registry (ghcr.io). You can pull the images using either of the following methods:
โ Docker Hub
docker pull wayofdev/php-base:8.3-fpm-alpine-latestโ GitHub Container Registry
docker pull ghcr.io/wayofdev/docker-php-base:8.3-fpm-alpine-latestReplace 8.3-fpm-alpine-latest with your desired PHP version, type, and tag.
โ Available Image Variants
The images are available in various combinations of PHP versions, types, and architectures:
- PHP Versions: 8.1, 8.2, 8.3, 8.4
- Types: cli, fpm, supervisord
- Architectures: amd64, arm64
Examples
# PHP 8.1 CLI
docker pull wayofdev/php-base:8.1-cli-alpine-latest
# PHP 8.2 FPM
docker pull wayofdev/php-base:8.2-fpm-alpine-latest
# PHP 8.3 with Supervisord
docker pull wayofdev/php-base:8.3-supervisord-alpine-latestFor a complete list of available tags, please refer to the Docker Hub Tags or GitHub Container Registry Packages page.
โ Using in Dockerfile
To use these images as a base for your own Dockerfile:
# From Docker Hub
FROM wayofdev/php-base:8.3-fpm-alpine-latest
# Or from GitHub Container Registry
# FROM ghcr.io/wayofdev/docker-php-base:8.3-fpm-alpine-latest
# Your additional Dockerfile instructions here
# ...๐จ Development
This project uses a set of tools for development and testing. The Makefile provides various commands to streamline the development process.
โ Requirements
- Docker
- Make
- Ansible
- goss and dgoss for testing
โ Setting Up the Development Environment
Clone the repository:
git clone git@github.com:wayofdev/docker-php-base.git && \
cd docker-php-baseโ Generating Dockerfiles
Ansible is used to generate Dockerfiles and configurations. To generate distributable Dockerfiles from Jinja template source code:
make generateโ Building Images
-
Build the default image:
make build
This command builds the image specified by the
IMAGE_TEMPLATEvariable in the Makefile. By default, it's set to8.3-fpm-alpine. -
Build a specific image:
make build IMAGE_TEMPLATE="8.3-fpm-alpine"Replace
8.3-fpm-alpinewith your desired PHP version, type, and OS. -
Build all images:
make build IMAGE_TEMPLATE="8.1-cli-alpine" make build IMAGE_TEMPLATE="8.1-fpm-alpine" make build IMAGE_TEMPLATE="8.1-supervisord-alpine" make build IMAGE_TEMPLATE="8.2-cli-alpine" make build IMAGE_TEMPLATE="8.2-fpm-alpine" make build IMAGE_TEMPLATE="8.2-supervisord-alpine" make build IMAGE_TEMPLATE="8.3-cli-alpine" make build IMAGE_TEMPLATE="8.3-fpm-alpine" make build IMAGE_TEMPLATE="8.3-supervisord-alpine" make build IMAGE_TEMPLATE="8.4-cli-alpine" make build IMAGE_TEMPLATE="8.4-fpm-alpine" make build IMAGE_TEMPLATE="8.4-supervisord-alpine"
These commands will build all supported image variants.
๐ง Configuration
Ansible is used to generate distribution files. To add or remove PHP extensions, or configure the project, you can modify the src/group_vars/base.yml file.
โ Default .ini settings for PHP
You can adjust the following PHP and OPcache settings in the group_vars/base.yml file:
settings_opcache_ini:
php_opcache_enable: 1
php_opcache_enable_cli: 1
settings_php_ini:
php_timezone: "UTC"
php_post_max_size: "16M"
php_memory_limit: "256M"โ PHP Extensions
You can enable or disable PHP extensions by modifying the following sections in the group_vars/base.yml file:
ext_native_enabled:
- intl
- pcntl
- sockets
- pdo_mysql
- pdo_pgsql
- OPcache
- zip
- bcmath
- exif
- gd
ext_pecl_enabled:
- redis
- memcached
- decimal
- amqp
- yaml
- grpc
- protobufTo add a new extension, simply add it to the appropriate list. To remove an extension, delete it from the list.
After making changes to the group_vars/base.yml file, you need to regenerate the Dockerfiles:
make generateThis command will use Ansible to process the updated configuration and generate new Dockerfiles with your custom settings.
๐งช Testing
This project uses a testing approach to ensure the quality and functionality of the Docker images. The primary testing tool is dgoss, which allows for testing Docker containers.
โ Running Tests
You can run tests using the following commands:
-
Test the default image:
make testThis command tests the image specified by the
IMAGE_TEMPLATEvariable in the Makefile (default is8.3-fpm-alpine). -
Test a specific image:
make test IMAGE_TEMPLATE="8.3-fpm-alpine"
Replace
8.3-fpm-alpinewith your desired PHP version, type, and OS. -
Test all images:
make test IMAGE_TEMPLATE="8.1-cli-alpine" make test IMAGE_TEMPLATE="8.1-fpm-alpine" make test IMAGE_TEMPLATE="8.1-supervisord-alpine" make test IMAGE_TEMPLATE="8.2-cli-alpine" make test IMAGE_TEMPLATE="8.2-fpm-alpine" make test IMAGE_TEMPLATE="8.2-supervisord-alpine" make test IMAGE_TEMPLATE="8.3-cli-alpine" make test IMAGE_TEMPLATE="8.3-fpm-alpine" make test IMAGE_TEMPLATE="8.3-supervisord-alpine" make test IMAGE_TEMPLATE="8.4-cli-alpine" make test IMAGE_TEMPLATE="8.4-fpm-alpine" make test IMAGE_TEMPLATE="8.4-supervisord-alpine"
โ Test Configuration
The test configurations are defined in goss.yaml files, which are generated for each image variant. These files specify the tests to be run, including:
- File existence and permissions
- Process checks
- Port availability
- Package installations
- Command outputs
- PHP extension availability
โ Test Process
When you run the make test command, the following steps occur:
- The specified Docker image is built (if not already present).
- dgoss runs the tests defined in the
goss.yamlfile against the Docker container. - The test results are displayed in the console.
๐ Security Policy
This project has a security policy.
๐ Want to Contribute?
Thank you for considering contributing to the wayofdev community! We are open to all kinds of contributions. If you want to:
- ๐ค Suggest a feature
- ๐ Report an issue
- ๐ Improve documentation
- ๐จโ๐ป Contribute to the code
You are more than welcome. Before contributing, kindly check our contribution guidelines.
๐ซก Contributors
๐ Social Links
- Twitter: Follow our organization @wayofdev and the author @wlotyp.
- Discord: Join our community on Discord.