Compose Files
100%

Docker Compose · Lesson 1

Compose Files

Learn to read a Compose file by finding its services, images, commands, and ports.

Running a web server and its helper with separate commands is manageable once. A Compose file keeps the settings together so you can start the same services again. This course assumes a Docker environment with the Compose plug-in, which provides the docker compose command.

Defining Two Services

In a new practice folder named journey-compose, save the following as compose.yaml. A service describes how Compose should run a container. This file defines a web server and a small toolbox that stays alive for later checks.

services:
  web:
    image: nginx:alpine
    ports:
      - "127.0.0.1:8080:80"
  toolbox:
    image: busybox:1.36
    command: ["sleep", "3600"]

Use spaces for indentation. The indented keys under web belong to that service. The dash under ports begins a list item. The brackets on command also form a list, here with the program name and its argument.

Which service uses the BusyBox image?

Reading the Web Service

The web service publishes host port 8080 to container port 80. On the machine running Docker, a request to http://127.0.0.1:8080 can reach Nginx after the service starts. The toolbox has no published port. Its sleep command keeps it running for 3,600 seconds during practice.

Which part of the file decides how a browser on the Docker host reaches Nginx?

Checking the Parsed Configuration

Run this command from the folder with the file. Type the command after the $ prompt. Compose reads compose.yaml and prints the configuration it understands. Look for the web and toolbox entries. It may expand short settings into longer forms when displaying them.

$ docker compose config

The command prints two services successfully. What have you verified?

Lesson complete

You finished Compose Files

You can now identify the parts of a simple Compose file.

  • Read the names and image references under services.

  • Relate a service's settings to the container it describes.

  • Inspect the parsed file with docker compose config.

Keep your learning progress

Create a free account to save this lesson and continue learning on any device.

Create a free account
Next Lesson
Back to Docker Compose