Back to course

Lesson 17: Installing and Setting up Docker Compose

Docker Zero to Hero: The Complete Containerization Course for Beginners

Lesson 17: Installing and Setting up Docker Compose

For most modern environments (Windows, macOS), Docker Compose is already included with Docker Desktop. Since version 2, the primary command is docker compose (without the hyphen, replacing the older docker-compose).

Verifying the Installation

Open your terminal and check the version. If you are using Docker Desktop, this command should work out of the box.

bash docker compose version

If you see version information, you are good to go.

Anatomy of the compose.yml File

Docker Compose uses YAML format for its configuration file. This file describes the services, networks, and volumes needed for the application.

Basic Structure

yaml version: '3.8' # Specifies the Compose file format version

services:

Service definitions go here (e.g., web, db, cache)

volumes:

Volume definitions go here

networks:

Network definitions go here

Key Components

  • version: Specifies the file format version (currently 3.8 is standard).
  • services: Defines the containers (or services) that make up your application. Each service corresponds roughly to a single docker run command.
  • image / build: Specifies whether to pull an image or build one from a local Dockerfile.
  • ports: Defines port mappings (-p).
  • environment: Sets environment variables (-e).
  • volumes: Defines persistent storage mappings (-v).

In the next lesson, we will build a full compose.yml file.