The Easiest Way to Dockerize PHP Applications

Docker Nov 29, 2021

What is the easiest way to dockerize PHP applications? Let's find out with the GitHub repository example.


In order to create scalable architecture, we will dockerize two apps that will use the same reverse proxy.


Services can only communicate with other services on networks they share, so we will have three networks:

  1. Proxy Network which contains Reverse Proxy (Nginx), Best App (Apache/PHP), and Awesome App (Apache/PHP);
  2. Best Network which contains Best App and Best DB (MySQL);
  3. Awesome Network which contains only Awesome App.


Requirements for our architecture are:

  1. There are no permission issues;
  2. Xdebug works out-of-the-box;
  3. Every application has a unique domain;
  4. We use HTTPS;
  5. Setup supports multiple applications.

Permission Issues and Xdebug

To prevent permission issues and have package availability out-of-the-box, we will use thecodingmachine/php for PHP applications, a general-purpose PHP image for Docker.

We will use its fat image, as it comes with Apache, Superconic, and Composer and it already has common PHP extensions enabled.

Unique Domains, HTTPS and Multiple Applications

In order to have unique domains, HTTPS and multiple applications support out-of-the-box, we will use nginx-proxy, as it supports everything mentioned above.

GitHub Repository

As we have defined the architecture and tools we will use, this is the part where you should visit and see how to configure and run everything mentioned so far.


This post could have been a lot longer, but I've kept it as short as possible because everything should be explained in the example repository.

Is the Easiest Way the Best Way?

It depends on what our goal is. If our goal is to create an optimized, clean and precise docker environment, then it's not the best way, as it's a fat setup. But if we want to dockerize our app for our local development in the fastest and hassle-free way, then it might be the best way to do it.