Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker separate containers vs coupled containers

I have a few dozens of php apps that I want to dockerize. I am wondering what will be the best design for management and performance wise.

  1. one big container with all services included (php-fpm, mysql, nginx etc)

  2. separate containers for all services:

    • container-php-fpm-app1
    • container-nginx-app1
    • container-mysql-app1
    • container-php-fpm-app2
    • container-nginx-app2
    • container-mysql-app2
  3. one container for service, that service hosts all apps:

    • container-php-fpm - for all php-fpm pools
    • container-nginx - for all nginx virtual hosts
    • container-mysql - for all databases

I understand running separate containers lets you make changes to one service without impacting another. You can run different php configurations and extensions and versions without worrying about the other services being affected. All of my apps are Wordpress based, so configuration will (or should) be consistent across the board.

For now I am leaning toward separation, however I am not sure if this is the best approach.

What do you guys think?

like image 986
Radoslav Stefanov Avatar asked Apr 27 '26 00:04

Radoslav Stefanov


2 Answers

You should run one service in a container, that's how it's designed. So 1 is out the door.

If you look at three, you have a tight coupling between your apps. If you want to migrate to a new php-version for app1, or have a different dependency there, you're in trouble, so that's not a good one.

The standard is to do 2. A container per service.

like image 192
Nanne Avatar answered Apr 29 '26 14:04

Nanne


Per docker documentation multi-service container:

It is generally recommended that you separate areas of concern by using one service per container. That service may fork into multiple processes (for example, Apache web server starts multiple worker processes). It’s ok to have multiple processes, but to get the most benefit out of Docker, avoid one container being responsible for multiple aspects of your overall application. You can connect multiple containers using user-defined networks and shared volumes.

Also based on their best practices:

Each container should have only one concern

Decoupling applications into multiple containers makes it much easier to scale horizontally and reuse containers.

I would suggest using option 2 (separate containers for all services).

like image 27
zstate Avatar answered Apr 29 '26 15:04

zstate



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!