📧 chinmayeepavi@gmail.com Support

Docker Compose

Compose defines and runs multi-container applications from a single YAML file, replacing long chains of docker run commands.

services:
  mongodb:
    image: mongo:6
    container_name: app-mongodb
    ports:
      - "27017:27017"
    volumes:
      - mongodb_data:/data/db
    networks:
      - app-network

  backend:
    build: ./app-api
    container_name: app-api
    ports:
      - "5002:5002"
    environment:
      - MONGO_URI=mongodb://mongodb:27017/app_db
    depends_on:
      - mongodb
    networks:
      - app-network

  frontend:
    build: ./app-ui
    container_name: app-ui
    ports:
      - "3000:3000"
    depends_on:
      - backend
    networks:
      - app-network

volumes:
  mongodb_data:

networks:
  app-network:
    driver: bridge
docker compose up -d           # create and start everything, detached
docker compose ps
docker compose logs -f backend
docker compose exec backend sh
docker compose build           # rebuild images
docker compose stop
docker compose down            # stop and remove containers and networks
docker compose down -v         # also remove named volumes

Note the service names. Because Compose puts all three services on one network, backend reaches the database at mongodb://mongodb:27017 — the service name resolves as a hostname. That is why no IP addresses appear anywhere in the file.

Modern Docker ships Compose v2 as the docker compose subcommand. The standalone docker-compose binary and the leading version: '3.8' key are both legacy; the version key is now ignored and can be deleted.