Shared containers on same host

Hello everyone,

I have a few legacy PHP applications (~ 12) that I want to run on the same host, a dedicated server.
My idea is to use a container as a reverse proxy (nginx or traefik) to accept all traffic and dispatch it to the relevant containers based on the hostname. All this can be done with docker-compose.

So my setup would be something like this

[reverse-proxy] => website1 [Nginx] + [PHP] + [MySQL]
=> website2 [Nginx] + [PHP] + [MySQL]
=> etc…

Now, something is bothering me: all these PHP applications use the same PHP version and required an access to a MySQL database. It seems rather inefficient to deploy a PHP container and a MySQL container for each of these applications as I would end up running on the same host around 12 PHP containers and 12 MySQL containers. Instead, I could just set up one MySQL container and one PHP container on a shared external network and for each website, the nginx container would access this network.

My question is: is this a good practice? I have not seen this kind of setup anywhere… I can see that it defeats the purpose to run everything in isolation but it seems to me easier to maintain this way. Also, should I expect issues if two nginx containers need access to the PHP or MySQL container at the same time?

Thanks!

Sharing the database could make sense, that’s standard procedure. Sharing the same PHP container seems rather unusual, as mostly you want to deploy new versions independently.

If code is not modified, you would need to look into options how to deploy the apps in the same container, maybe using different folders. There is a PHP container with Apache included, so you would only need proxy + php/apache + database.