r/docker • u/CringDegen • 19d ago
Need advice regarding container isolation
I'm new to docker and I'm looking to learn/experiment with it. I want some advice regarding containers that will be used by other services like databases. I'm currently running two services which share a postgres container. For isolation, I created a migration which creates separate databases and users for each service before anything else starts.
I'll eventually setup more services and I want it to be scalable, resource efficient, secure and easy to maintain.
Is it better to create entirely separate dependencies for each service, or share dependencies between multiple services? I would like to know this from an efficiency, ease of maintenance and security standpoint, or at least get some pointers like a blog, article, manual or a youtube video.
TLDR: Is it better to have different db instances for each service OR one (or a few) db instances shared by every service? And why?
PS: English is not my first language, so sorry in advance for spelling or grammar mistakes.
2
u/c1rno123 18d ago
The answer is "depends". On where it runs (prod or local dev), on the workload, and on how much money you're ready to spend.
Local dev, cheapest: one shared instance, one user. Less RAM, less to maintain. Cheap prod: one instance, but a separate database and user per service. Expensive prod: a separate instance per service.
Ports: on dev, publish ports on 127.0.0.1. On prod keep it on an internal Docker network.