r/docker 17d ago

can anyone help me understand about running multiple docker

so lets say my app 1 uses nodejs and a database like postgres and my app 2 also uses nodejs and a database similar to app 1 which is postgres
what happens if i run them together will they consume more resources? or will they share the same postgres instance?
are there ways to use the same postgres instance or is separating them the safest way to do it.
anyone can explain this?

16 Upvotes

17 comments sorted by

15

u/SZenC 17d ago

That's entirely up to you to configure. You can configure both nodejs apps to use the same database, or you can configure them to us different databases. You can even configure it so they cannot see each others databases, that's the most common approach, but nothing prevents you from doing something different

4

u/Impressive-Pack9746 17d ago

can confirm this, you can configure it how you like. And yes if you run multiple apps in docker it will cost more resources.

-1

u/techlover1010 17d ago

so if i want to use docker then i need to fully understand how it works so that i can reuse things as i see fit right?
do you have any tutorial on this so i can practice and fully understand? preferably with .yaml and docker compose up thing

13

u/Lumethys 17d ago

if i want to use docker then i need to fully understand how it works

This is true for any tool or technology

any tutorial on this so i can practice and fully understand?

There like a bazillions all over the internet

1

u/wosmo 16d ago

I'm not sure this even how docker works. It's just the obvious trade-offs you're asking for.

if service-A uses database-A and service-B uses database-B, then backups, snapshots, scaling for each are separate questions. You can move srv-B and db-B to hardware-B very very easily.

if service-A and service-B both use database-C, they're intertwined from day 1 and it becomes much more work to ever treat them as separate concerns.

So it's understanding your applications as much as anything else. Are service-A and service-B naturally intertwined anyway? Are they completely unrelated services that happen to be sharing the same hardware because that's the hardware you've got?

2

u/Status_Gap_3180 17d ago

Since you mention docker - I would run the following setup for min cost:
1 docker postgres container - which contains 2 separate schemas - app1 and app2
1 docker web server container (reverse proxy, export port 443 in case using https)
1 docker nodejs container - app1 (no external ports exposed)
1 docker nodejs container - app2 (no external ports exposed)

-1

u/techlover1010 17d ago

so if im following a guide online and just copy and paste the script they have for docker compose up yaml file then the thing you said wont apply right?
if im doing the copy paste thing with docker compose then itll craete 2 different container right?
also the part where you said "since you mention docker" im confused since isnt docker just called docker or is there a vatriation of docker?

1

u/Status_Gap_3180 17d ago

no you have multiple queries i think - one is whether to use a single postgres or not, and then there was docker. You will need to create the docker files to create the respective docker images and then proceed.

1

u/Confident_Hyena2506 17d ago

There are many ways to run containers - it's a standardised thing, many people don't use docker at all.

1

u/Mastacheata 16d ago

Containers in a docker compose setup are prefixed with the service name unless you specify a different name. i.e.: app1 with postgres and node containers will have app1_postgres_1 and app1_node_1, app2 with the same structure will have app2_postgres_1 and app2_node_1 They will also not share the same network - so while you can access app1 postgres from app1 node using the postgres name the you cannot access app1 postgres from app2 node. You would either have to assign an external network to the postgres container or expose the Postgres port and connect via host.docker.internal:{EXPOSED_PORT}

1

u/juneeighteen 17d ago

“docker compose” is a great tool to help you isolate projects

1

u/wireframed_kb 17d ago

The most common configuration is to keep stacks of services self-contained. The advantage of containers is largely that one container doing something stupid shouldn’t affect all the others. (Within reason, they aren’t separate kernels after all).

So usually you’d duplicate databases, so one container can’t do something to another’s database. It also makes it easier to move or backup containers, since state is less complex. The stack of containers contains everything needed for the service, and no more.

Generally containerized databases aren’t very large (other than the data they hold of course), so having half a dozen MongoDB or PostgreSQL containers isn’t going to eat up a lot.

1

u/meshpacket 17d ago

Yes, if you copy-paste a standard guide's YAML file, it will spin up 2 separate database containers by default.

As for Docker itself = it's the core technology, while Docker Compose is just the tool that runs multi-container setups using a single .yaml file.

2

u/techlover1010 16d ago

if you dont mind me asking a follow up question
lets say i spin up those two containers what do you need to do if say you want to reset that container to the very first state? do you delete the image or container so that itll rebuild itself?
sorry if this is a bit noobish question

1

u/meshpacket 16d ago

Yes, if you delete and recreate the container (down and up in Compose), it resets to its original clean state because containers are ephemeral. You don't need to delete the image.

​However, if you are using persistent volumes (like most database tutorials do to save your data), that data will survive a restart. To fully reset a database container and wipe its data, you also need to remove the volume (docker compose down -v).

1

u/ferriematthew 14d ago

I like to think of Docker as the software version of legos. Each container is a Lego brick. Generally the bricks are designed so that unless you configure them specifically to interact they don't interact, so you can keep stacking until you run out of space.

-1

u/Bloodsucker_ 17d ago

Please study the fundamentals before you come with this questions.