Now that we have covered all major Docker concepts, in a real-life scenario with our three images:
we would run all three together using Docker Compose.
In a real application, we typically have multiple services running together:
Node.js App
MongoDB
Mongo ExpressEach service runs in its own container.
We can define all three services in a single docker-compose.yaml file.
services:
mongo:
image: mongo
ports:
- 27017:27017
environment:
MONGO_INITDB_ROOT_USERNAME: admin
MONGO_INITDB_ROOT_PASSWORD: qwerty
mongo-express:
image: mongo-express
ports:
- 8081:8081
environment:
ME_CONFIG_MONGODB_ADMINUSERNAME: admin
ME_CONFIG_MONGODB_ADMINPASSWORD: qwerty
ME_CONFIG_MONGODB_URL: mongodb://admin:qwerty@mongo:27017/
node-app:
build: .
ports:
- 5050:5050
depends_on:
- mongoUser
↓
Node.js App (Container)
↓
MongoDB Container
↑
Mongo Express Container (UI)mongo)docker compose up -ddocker compose downInstead of manually running multiple commands like:
docker run mongo
docker run mongo-express
docker run node-appWe simply run:
docker compose up -dThis is exactly how real-world backend systems are structured:
All connected through Docker networking and managed using Docker Compose.