<p>Keep the DB containers separate. The concept of microservices and containers is to allow each part to be independently updated without introducing changes and outages to the rest of the application stack. Containers should also be running a single app per container to allow error detection and log gathering from that application. Each container is simply an isolated process, so unlike a VM, there's little overhead on the host to split each of these out.</p>

CC BY-SA 4.0
2018-07-24T14:23:13.540Z
2018-07-24T14:23:13.540Z
BMitch
<p>I am implementing a simple setup with two micro services and would like each of them to have their own DB - each service is running in it's own container.
Should i include the DB's in each service container (so each container will contain the service application + DB with a total of two containers), or should i create a new container for each DB (with a total or four containers)?.
Given the fact that each DB is used only by one service, it seems cleaner to encapsulate the Service+DB in a single container which will be the overall service. On the other hand - deploying a DB as a container is much simpler and faster than combining it with the application container.</p>

<docker><containers><microservices><databases>
In a Database Per Service model - should i include the database in the service container?
ABR
# In a Database Per Service model - should i include the database in the service container?

(Asked by: username_0 on 2018-07-24)

I am implementing a simple setup with two micro services and would like each of them to have their own DB - each service is running in it's own container.
Should i include the DB's in each service container (so each container will contain the service application + DB with a total of two containers), or should i create a new container for each DB (with a total or four containers)?.
Given the fact that each DB is used only by one service, it seems cleaner to encapsulate the Service+DB in a single container which will be the overall service. On the other hand - deploying a DB as a container is much simpler and faster than combining it with the application container.

**Tags:** docker, containers, microservices, databases


---

## 1 answers

### Answer by username_1 on 2018-07-24. Score: 3 | Accepted answer

Keep the DB containers separate. The concept of microservices and containers is to allow each part to be independently updated without introducing changes and outages to the rest of the application stack. Containers should also be running a single app per container to allow error detection and log gathering from that application. Each container is simply an isolated process, so unlike a VM, there's little overhead on the host to split each of these out.


---

