L H
L H

Reputation: 1275

Docker - Best practice for database containers?

I have a running postgreSQL container and I would like to start another dockerised application that needs a database. Should I be using the same postgreSQL container or spin up a separate one (the second application is completely unrelated to the first in any way)?

What's the best practice here?

Upvotes: 5

Views: 2492

Answers (4)

eric roberts
eric roberts

Reputation: 31

You should use two different containers separately for creating the application and Postgresql.

Reasons:

  1. When you need Postgresql with another application that you develop in future, for that you will need to start the container. Now if your old application and database are in same container, it will also start the first application which you might no want.

  2. You can use the same container with multiple applications. ( Only for small applications)

  3. You can scale up the database when in different container.

Upvotes: 1

Adiii
Adiii

Reputation: 59946

When it comes to Docker or microservices, the relation between services should be independent, the more service is independent the more room for scalability and flexibility.

There are many things that you can consider and that will lead to go for separate DB container

  • What if using single DB container and if that went down your both app will be down
  • Upgrading DB container for app A will result breaking changes or effort in app B
  • You will not able to scale DB for one app, will require more resources
  • Having a single DB for each App will lead to less dependency and many more things from an infrastructure point of view you can consider.

Upvotes: 5

Adi Dembak
Adi Dembak

Reputation: 2536

Separate services, or apps, should use different containers. Otherwise you are placing unneeded constraints on yourself.

What if, for example, tomorrow you need replicate App2 and scale it out quickly ? If the app has its own db container, that task is much simpler.

Upvotes: 3

Mohsin Amjad
Mohsin Amjad

Reputation: 1209

Seperate containers with seperate volume mounts. As your application is unrelated you don't want app 1 to change db data of app 2 and vice versa.

Upvotes: 0

Related Questions