compose.yaml & service names

Declare two services with Compose

Lesson 13 of 20 · 12 min · Module 4: Artifact and stack design

A declarative file can describe the relationships of a small application stack.

Start this lesson →

Free. No installation: you write and run the code in your browser, and it is checked automatically.

By the end, you’ll be able to…

  • Describe the desired service graph
  • Keep YAML data types visible

The idea

Compose describes services and their relationships as YAML mappings and sequences. Read the whole service graph, including access and storage boundaries.

services:
  frontend:
    image: nginx:1.27-alpine
    ports: ["9090:80"]

01Describe the desired service graph

The services mapping gives each service a stable name. Compose supplies a default network so services can address one another by those names.

02Keep YAML data types visible

Quote port strings to make their meaning unambiguous. Environment values can be described as a mapping, with one name and value per entry.

03Check exposure at the stack boundary

Only api needs a host entry point here. The cache remains addressable on the application network without publishing a separate host port.

Your turn

Define services api (image notes:1.0) and cache (image redis:7-alpine). Publish api as 8080:3000, set REDIS_HOST to cache, and keep cache without published ports.

What the checks look for

  • Defines both images
  • Publishes the API and discovers cache
  • Keeps cache internal
Try it in the editor →

Take this with you

Describe the service graph and expose only its intended entry points.

Go a little further

Add a second API environment variable using either supported environment syntax.

Learn Docker & Containers for free

20 short lessons with real code and instant checks.

See the whole course →