Docker: Create Automated PHP Images

Docker is the buzzword for a while now. At work, we are using Docker for our website development and on continuous integration tools. It provides us an easy and fast way to get new developers local development environment up and ready.

Our team is using php7 and Slim Framework to develop PHP apps. To make the experience even better we built a docker image hierarchy which we extended from official base php7 image, and created our own “base” image.

Our docker php7 base repository has some PHP extensions, composer, some vhost files, some basic php.ini configuration, mysql extension and XDebug installed. This is pretty much the things we always need when developing any application.

image showing menu link to create automated build on docker hubFinally we set up an automated build on docker hub to have it built for us whenever we push to master branch. Here you have to authorise docker hub to access the GitHub repositories. Then pick the repository you have the Dockerfile committed. Another configuration we have here is to get another automated build triggered whenever official php image has a new release as well.  This enables us to get latest 7.0.* versions automatically upgraded in the image we are using.

image showing the config page for repository links on docker hub

For more information about docker hub automated builds, you can also check out their official documentation.

Now the fun part. The idea with this base image was, to have it ready to be extended for more specific use. For example we have php7-slim repository, which is extending base php7 image and enabling slim vhost configuration and adding slim framework requirements, and has its own automated build. Has the same link as above, but this time to php7-base image itself. Similarly, php7-drupal extends php7-base image with Drupal requirements and has its own automated build. And then another project can join and extend it once more.

The resulted docker image hierarchy is working well, and we are getting minor php upgraded to our development environment automatically, because a change in base image causes chain triggers to rebuild parent images. We can also use this to add more php extensions to all Slim Framework projects for example, or optimise composer, or update php.ini config for all docker images we use in all teams in a central location…

We are then using final images in docker-compose configuration yaml files.

Simple, and fun.

One Reply to “Docker: Create Automated PHP Images”

Leave a Reply

Your email address will not be published. Required fields are marked *