Docker Community Forums

Share and learn in the Docker community.

Shared CMS with multiple projects

Hi,

I’m currently using Docker for small projects that are running apache, PHP and mariaDB.
Each project has their own docker-compose.yml.
In combination with traefik and dnsmasq I’m able to create custom domain names for each project.

Now I’m looking into running our own CMS in docker.

Folder structure:

-- cms-sites
   -- _cms
      -- index.php
   -- cms-project-1
   -- cms-project-2
   -- cms-project-3

The issue that I’m running into is that each project is trying to require the index file for the CMS by navigating up some folders all the way to “_cms/index.php”.
This of course is impossible because each project is running its own server.

At first I thought I could solve this by simply create a server with cms-sites as root and create vhosts for each project. This is actually how it is working on the live server.
But from what I have read online this is not a good idea because the Docker container would become too big with all those projects. is this true?

Would I be able to solve my problem by adding another php-apache service inside my docker-compose.yml for a project where I also host the CMS?
Or could this be fixed by adding another volume to the current php-apacher service?

I’m currently running this locally in MAMP PRO but the issue there is that I want to use a specific php and mariaDB version so that is why I’m looking at docker as a solution.

This is not the main reason and all depends on what you mean by big. If you have multiple applications in one container, then updating those applications are more complicated. For example to change the sourcecode of one app in the image you need to restart each of them. The other problem is handling dependencies. You add something to one of the applications which can break the others. Sometimes you need to scale the application running more instances without running more of the others. I just picked some examples but I hope you have got the idea.

In my opinion there is nothing wrong with starting the learning process with the same approach as you had before but now inside a container as long as you remember it shouldn’t be the final version. In this case however, You could just restructure your projects a little. Create a base image containing the common code like a framework and create a new image for each application the rest of the codes inside the container.

Dockerfile.base

FROM php:YOUR_PREFERRED_VERSION
COPY src/base /var/www/html
# ...
docker build -t app-base -f Dockerfile.base  .

Dockerfile.app1

FROM app-base
COPY src/app1 /var/www/html
# ...
docker build -t app-1 -f Dockerfile.app1 .

You could do better but I wanted to keep the example simple. The right solution depends on your apps.