05 Docker Compose - Jermmyy/IT-Landscape GitHub Wiki

Docker Compose

Docker Compose is a tool used to define and run multi-container Docker applications. With Compose, you can use a YAML file to configure your application’s services, networks, and volumes and then start everything with a single command.


Why Use Docker Compose?

  • Easier multi-container setup, great for applications with databases, backends, frontends, etc.
  • Reusable and shareable config — define the app once in a docker-compose.yml file.
  • Simplifies orchestration — bring everything up/down with just one command.

Example: Node.js + MongoDB

Here is a simple setup with a Node.js app an a MongoDB container:

version: "3.9"

services:
  app:
    build: .
    ports:
      - "3000:3000"
    depends_on:
      - mongo

  mongo:
    image: mongo:6.0
    ports:
      - "27017:27017"
    volumes:
      - mongo-data:/data/db

volumes:
  mongo-data:

Explanation

Key Description
version Defines the Docker Compose file format version.
services Lists all the containers used in the app.
app Custom-built container (e.g. your Node app).
mongo Uses the official MongoDB image from Docker Hub.
depends_on Ensures the mongo service starts before app.
volumes Creates a named volume to persist MongoDB data.

Run Your App

Once your docker-compose.yml is ready, start everything with:

docker-compose up --build

To stop the containers:

docker-compose down

alt text