# Single versus multiple containers

**URL:** <https://forums.docker.com/t/single-versus-multiple-containers/12458>\
**Category:** General\
**Tags:** docker\
**Created:** [May 17, 2016, 3:06pm UTC](https://forums.docker.com/t/single-versus-multiple-containers/12458 "2016-05-17T15:06:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![yashgt](https://avatars.discourse-cdn.com/v4/letter/y/bcef8e/32.png) [@yashgt](https://forums.docker.com/u/yashgt)\
**Post date:** [May 17, 2016, 3:06pm UTC](https://forums.docker.com/t/single-versus-multiple-containers/12458/1 "2016-05-17T15:06:46Z")

</div>

Hi,

I have 2 processes P1 and P2 in my System that communicate very frequently with each other over TCP. For this reason they are both hosted on the same VM. I am thinking of eliminating the VM and instead hosting my System in containers on the physical machine. If I dockerize my System, I have 2 options:

1. Container 1 contains P1, Container 2 contains P2. The 2 containers will be linked. The communication between P1 and P2 will be across container boundary.
2. One single Container will contain P1 and P2. The communication will remain within the container.

Kindly guide me on the merits and demerits of the above 2 approaches. What is the overhead involved in terms of communication latency in approach 1?

Thanks,  
Yash

---

<div class="post-metadata">

**Author:** ![aleveille](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/aleveille/32/9905_2.png) [@aleveille](https://forums.docker.com/u/aleveille)\
**Post date:** [May 17, 2016, 3:33pm UTC](https://forums.docker.com/t/single-versus-multiple-containers/12458/2 "2016-05-17T15:33:00Z")

</div>

It is a best practice to run only one process per container:

> **[Best practices for writing Dockerfiles](https://docs.docker.com/engine/userguide/eng-image/dockerfile_best-practices/#run-only-one-process-per-container)**
>
> Docker can build images automatically by reading the instructions from a Dockerfile, a text file that contains all the commands, in order, needed to build a given image. Dockerfiles adhere...

As for the latency in approach 1: given that they will run on the same physical machine, latency will be extremely small

---

<div class="post-metadata">

**Author:** ![dmaze](https://avatars.discourse-cdn.com/v4/letter/d/ea5d25/32.png) [@dmaze](https://forums.docker.com/u/dmaze)\
**Post date:** [May 17, 2016, 4:12pm UTC](https://forums.docker.com/t/single-versus-multiple-containers/12458/3 "2016-05-17T16:12:53Z")

</div>

> [@aleveille](#):
>
> It is a best practice to run only one process per container:  
> [Overview of best practices for writing Dockerfiles | Docker Docs](https://docs.docker.com/engine/userguide/eng-image/dockerfile_best-practices/#run-only-one-process-per-container)
> 
> As for the latency in approach 1: given that they will run on the same physical machine, latency will be extremely small

Adding to this: the communication latency of the two approaches will be almost identical (no matter how you set up the containers, the two processes will be communicating via on-box TCP), but the one-process-per-container setup will be much easier to build, since Docker can natively run one process per container without you having to go out of your way to install some sort of init system into the container.
