Docker PHP App Base Container
In a previous post about Docker base containers in general I had described different ways of deploying code with Docker containers and how we use them at CloudObjects. Today I’d like to describe one of those base containers, specifically one for PHP applications. The container is called
cloudobjects/php-app-base and it’s public if you want to try it for your own PHP apps. You can see it on the Docker Hub where it’s being built automatically and transparently in Docker’s trusted environment, and also there’s the underlying GitHub repository with the Dockerfile for this image.
So here’s how to use it.
During development you can mount the source of your application like this:
docker run cloudobjects/php-app-base -p 80:80 -v /path/to/source:/var/www/app
When you have a ZIP file built with your application’s source code as a deployment package you can ask the container to download and install this file at runtime like this:
docker run cloudobjects/php-app-base -p 80:80 -e PACKAGE_ZIP_URL=http://example.com/source.zip
A good practice for organizing PHP projects, which is also required by this Docker image, is that the webserver is not pointing to the root of your application but to a separate
web directory within that application root instead. This way you can make sure that all requests go either to an entrypoint
index.php in that directory or a static file you want to serve and not directly to a file that you might not want to expose publicly, such as your
composer.json or your test cases. This means that you should set up your projects like this. If you haven’t you can still use this container, but you have to put the whole application under
The image is built with PHP 7. As there are some applications with legacy code that don’t run under PHP 7 there’s also a second version of the image built with PHP 5.6. If you want that one, simply replace
php-app-base:5 in the examples listed above.
Happy coding and deploying :)