It is a lot of work to build PHP containers over and over again, let alone the wait for containers to build. This project makes that life easier by providing fully reusable PHP base containers and extensions.
The main idea behind this project is based on the Bref development containers. This project provides a base PHP or PHP-FPM container and many prebuild extensions. All you have to do, is combine them into your own project.
Using this project is fairly easy. You start your Dockerfile with the base container. The base containers life in registry ghcr.io/xip-online-applications/php-docker-containers/php
and are versions like this: <PHP VERSION>[.<CONTAINER RELEASE VERSION>][-fpm]
. Example for PHP-FPM version 8:
FROM ghcr.io/xip-online-applications/php-docker-containers/php:8.1-fpm
Now lets say you want to use the extensions MySQL and Redis. Each extension lifes in its ow registry like ghcr.io/xip-online-applications/php-docker-containers/php-extra-mysql
for MySQL. The versionsing is the same as with the base image; <PHP VERSION>[.<CONTAINER RELEASE VERSION>]
. All you have to do is copy the /opt
dir from the extension image to the /opt
directory in your image. You can add them to your Dockerfile like this:
COPY --from=ghcr.io/xip-online-applications/php-docker-containers/php-extra-mysql:8.1 /opt /opt
COPY --from=ghcr.io/xip-online-applications/php-docker-containers/php-extra-redis:8.1 /opt /opt
Now if you want to use some development tools like xDebug and use development settings, you can use the ghcr.io/xip-online-applications/php-docker-containers/php-extra-dev
image:
COPY --from=ghcr.io/xip-online-applications/php-docker-containers/php-extra-dev:8.1 /opt /opt
To undo these dev settings, you can use the ghcr.io/xip-online-applications/php-docker-containers/php-extra-prod
AFTER the dev extension.
Check the example directory for a fully working example of the above within a multi-stage build.
See the list of available extensions below:
Extension | Container | Notes |
---|---|---|
amqp | ghcr.io/xip-online-applications/php-docker-containers/php-extra-amqp | |
bcmath | ghcr.io/xip-online-applications/php-docker-containers/php-extra-bcmath | |
composer | ghcr.io/xip-online-applications/php-docker-containers/php-extra-composer | |
curl | ghcr.io/xip-online-applications/php-docker-containers/php-extra-curl | |
datadog | ghcr.io/xip-online-applications/php-docker-containers/php-extra-datadog | |
gd | ghcr.io/xip-online-applications/php-docker-containers/php-extra-gd | |
intl | ghcr.io/xip-online-applications/php-docker-containers/php-extra-intl | |
mbstring | ghcr.io/xip-online-applications/php-docker-containers/php-extra-mbstring | |
mongodb | ghcr.io/xip-online-applications/php-docker-containers/php-extra-mongodb | |
mysql | ghcr.io/xip-online-applications/php-docker-containers/php-extra-mysql | |
nodejs | ghcr.io/xip-online-applications/php-docker-containers/php-extra-nodejs | Versioning based on node versions: 14, 16, 18 and 19 |
opcache | ghcr.io/xip-online-applications/php-docker-containers/php-extra-opcache | |
pcntl | ghcr.io/xip-online-applications/php-docker-containers/php-extra-pcntl | |
rdkafka | ghcr.io/xip-online-applications/php-docker-containers/php-extra-rdkafka | |
redis | ghcr.io/xip-online-applications/php-docker-containers/php-extra-redis | |
saxonc | ghcr.io/xip-online-applications/php-docker-containers/php-extra-saxonc | Only for PHP version 7.4 |
xdebug | ghcr.io/xip-online-applications/php-docker-containers/php-extra-xdebug | |
xml | ghcr.io/xip-online-applications/php-docker-containers/php-extra-xml | |
xsl | ghcr.io/xip-online-applications/php-docker-containers/php-extra-xsl | |
zip | ghcr.io/xip-online-applications/php-docker-containers/php-extra-zip |
There are also some environment specific extensions available:
Extension | Container | Notes |
---|---|---|
dev | ghcr.io/xip-online-applications/php-docker-containers/php-extra-dev | Will set some development PHP settings and add xDebug |
prod | ghcr.io/xip-online-applications/php-docker-containers/php-extra-prod | Will undo dev extension settings |
First you need to prepare your local environment by preparing buildx:
docker buildx create --name php-docker-containers --use --bootstrap --platform linux/amd64,linux/arm64 --driver docker-container
Also authorize to the Github registry with your Github PAT:
echo "$GITHUB_TOKEN" | docker login ghcr.io -u "$GITHUB_ACTOR" --password-stdin
To develop a new extension, you need to make sure you do the following:
- Add the extension to the `src/extensions directory (like the others)
- Make sure your extension image is based on
scratch
with a copyable/opt
directory - The build of your extension is added to
.github/workflows/build-extensions.yaml
- Add the extension to the
README.md
file at sectionAvailable extensions