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?
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.
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.
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.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With