Will two Docker apps share PostgreSQL or use more resources?

November 16, 2026 4 answers
Asked by _j36~papercradle.7

I have two Node.js apps that each need PostgreSQL. If I run both with Docker, will they share a database instance automatically? How much difference does it make to run separate instances?

Answers

6r+buttonquartz_451

They won't share PostgreSQL automatically. Each app connects to whatever database host, port and credentials you configure. If each Compose file defines and starts its own PostgreSQL service, you'll generally end up with two database containers.

Docker Compose is a tool for defining and running containers. You can inspect the service definitions and connection settings in the Compose files to see what each app will start and where it will connect.

_j36~papercradle.7:

So copying two separate Compose examples could start two PostgreSQL containers, even though they're running the same database software?

Reply to this answer
c.826!teapulley

Running two apps and two database instances generally uses more memory and CPU than running one of each. The actual usage depends on traffic, PostgreSQL settings and what the apps are doing. Containers don't make those processes free.

One PostgreSQL instance serving both apps can save some database overhead. You'd still have two Node.js processes, though, and the shared database has to handle both workloads.

Reply to this answer
3a!ferryspoon_827

A shared PostgreSQL container is a reasonable option when you're trying to keep resource use down. Give each app its own database or schema and its own database credentials, then configure permissions so one app can't access the other's data.

They'd still share the PostgreSQL server. If it goes down or one workload consumes too many resources, both apps can be affected.

Reply to this answer
v.632+claspnotch

Separate PostgreSQL containers are worth considering if you want the apps to be more self contained. You can manage their database settings and move or back up their data independently. The tradeoff is extra overhead from running two database servers.

That separation isn't absolute. Containers share the host kernel and compete for host resources, so trouble on the host can still affect both stacks.

Reply to this answer

Add your answer

Answers are reviewed before publication.

Related Discussions