Reputation: 1275
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
Reputation: 31
You should use two different containers separately for creating the application and Postgresql.
Reasons:
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.
You can use the same container with multiple applications. ( Only for small applications)
You can scale up the database when in different container.
Upvotes: 1
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
Upvotes: 5
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
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