Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker - Best practice for database containers?

Tags:

docker

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?

like image 707
L H Avatar asked Jul 11 '20 03:07

L H


People also ask

Is it a good idea to Dockerize a database?

Docker is great for running databases in a development environment! You can even use it for databases of small, non-critical projects which run on a single server. Just make sure to have regular backups (as you should in any case), and you'll be fine.

Are containers good for databases?

They need both portability and elastic scaling, and containers are the best way to accomplish those goals. Databases need the advantages containerization brings, especially if the database is deployed in more than one place.

Where should I store Docker data?

Volumes are stored in a part of the host filesystem which is managed by Docker ( /var/lib/docker/volumes/ on Linux). Non-Docker processes should not modify this part of the filesystem. Volumes are the best way to persist data in Docker. Bind mounts may be stored anywhere on the host system.


2 Answers

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.
like image 121
Adiii Avatar answered Oct 06 '22 07:10

Adiii


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.

like image 38
Adi Dembak Avatar answered Oct 06 '22 06:10

Adi Dembak