3

When designing application infrastructure & architecture using Docker, is it best practise to create one container per "service" or multiple containers for each process within a "service"?

For example a distributed PHP application that uses Nginx, PHP-FPM, Redis, MySQL and ElasticSearch.

Service containers:

  • Nginx + App + PHP-FPM (complete app as a "service" container)
  • Redis
  • MySQL

Process Containers:

  • Nginx
  • App
  • PHP-FPM
  • Redis
  • MySQL

From my perspective it seems more maintainable to use a "service" container approach as managing so many discreet containers for each process could become cumbersome.

dnephin
  • 25,944
  • 9
  • 55
  • 45
AndrewMcLagan
  • 13,459
  • 23
  • 91
  • 158
  • I'm not that familiar with PHP-FPM, but wouldn't your app run in the PHP-FPM process? Or is it not a php interpreter? – dnephin Dec 04 '15 at 22:42
  • Possible duplicate of [Use of Supervisor in docker](https://stackoverflow.com/questions/33117068/use-of-supervisor-in-docker) – Mike Doe May 30 '18 at 12:28

1 Answers1

1

Container are all about isolation (isolation of filesystem, CPU, memory).
That also include isolation of process (one per container).

One process per container is easier to debug in case of failure (as oppose to connect to a huge container with tons of processes and different log running).
The upgrade/rollback path is easier (you only stop/restart one container per process you want to change).

Plus, whenever you have multiple processes running, you must use an image specialized in dealing with how those processes will stop: see "PID 1 zombie reaping issue".

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250