The Component Workshop Make it practical04 / 04

SECTION 02 · 10 MIN READ & EXPLORE

Give an idea somewhere to run

Turn an explanation into an experiment with steps, source files, predictions, and observable results.

DEMONSTRATION CONTENT

A lesson starts with a question and gives the learner a way to investigate it. The components below keep that investigation together. Commands run in the learner’s terminal; the website does not execute them.

Start with a problem

HANDS-ON LAB 5 min

Make a tiny Compose experiment

You want a repeatable way to run a command without installing its runtime on your laptop. Can a small Compose file describe the experiment?

Before you start

  • Docker with Compose installed and running.
  • An empty working directory and a terminal.

Your mission

  • Inspect the configuration before running it.
  • Run the container and compare its output with your prediction.
  • Change one value and explain the result.

Experiment files

compose.yaml

services:
  hello:
    image: alpine:3.22
    command: ["echo", "Hello, curious engineer."]

verify.sh

#!/bin/sh
set -eu
output=$(docker compose run --rm hello)
printf '%s\n' "$output"
printf '%s\n' "$output" | grep -Fx 'Hello, curious engineer.'
echo 'Verified: the container printed the expected message.'
CHECK YOUR UNDERSTANDING

What will this container do?

Read compose.yaml. What will appear in your terminal, and will the container keep running afterward?

Try your own explanation first. These notes stay on this page and are not saved or graded.

Show explanation

The container runs the command in the Compose file, prints Hello, curious engineer., and exits when that command finishes. A container can do a short task; it does not have to be a long-running server.

Run, observe, change

  1. Save the configuration

    Host terminal

    Download compose.yaml into an empty directory. Check that Compose can read it:

    docker compose config

    Expected observation

    Compose prints the resolved configuration. It has one service named hello.

  2. Run the experiment

    Host terminal
    docker compose run --rm hello
    The command failed. What should I check?

    Confirm Docker is running, that docker compose version works, and that your current directory contains compose.yaml. Read the error before changing the configuration.

    Expected observation

    You see Hello, curious engineer.. The command returns to your shell. The first run may also print image download progress.

  3. Change one thing

    Text editor, then host terminal

    Replace the message in command with your own. Predict the new output, then run the same command again.

    Show an example change

    Change the command to echo Hello from my experiment.. Run docker compose run --rm hello again. The container should print Hello from my experiment..

    Expected observation

    The output matches your new message. Explain which setting changed and which settings stayed the same.

How to know it worked

  • The container prints the message from the Compose file and exits.
  • Changing the command changes the output on the next run.

Before editing the original message, you can download verify.sh from its file tab and run sh verify.sh in the same directory. It checks the original output. After changing the message, explain why that check fails and update the check to match your intended result.

Leave the environment clean

docker compose down

This removes the experiment’s Compose network if one was created.

Download compose.yaml

Use callouts for consequential details

Authoring reference

Files from the lab itself

<CodeFiles title="Application files" files={[
  { src: "/labs/hello/compose.yaml" },
  { src: "/labs/hello/verify.sh", lang: "bash" }
]} />

Files are read at build time from public/labs/. Tabs support arrow keys, Home, and End. All files remain readable without JavaScript and when printing. A single file has no tab controls. Use name to override a displayed filename, or provide { name: "example.sh", code: "echo hello", lang: "bash" } for a short inline example.

A step with an observation and a hint

<Steps title="Inspect the service">
  <Step title="Send a request" location="Host terminal">

    Run `curl http://localhost:8080`.

    <div slot="expected">

    The response contains your application’s greeting.

    </div>

    <Reveal title="Connection refused?">

    Check whether the service is running and which port it publishes.

    </Reveal>

  </Step>
</Steps>

Steps stay visible together. Use location to distinguish host, container, and remote-server commands.

A prediction with an explanation

<Checkpoint title="Will the data survive?">

What happens if you replace the container but keep its named volume?

<div slot="explanation">

The replacement container can mount the existing volume and read its data.

</div>

</Checkpoint>

The response field is optional for the learner. Notes are not stored or graded, and the explanation can be opened whenever needed. Reveal also accepts kind="hint", kind="solution", or kind="explanation", plus open to start expanded.

A lab with clear boundaries

<Lab
  title="Restore a missing player"
  scenario="A recent commit removed a player from the squad."
  prerequisites={["Git installed", "The prepared exercise repository"]}
  objectives={["Find the relevant commit", "Restore only the affected file"]}
  success={["The player is present again", "The recovery is committed"]}
>

Add Markdown, Steps, Checkpoints, and CodeFiles here.

<div slot="cleanup">

Explain how to leave the exercise environment clean.

</div>

</Lab>

Lab also accepts a verification slot for commands or evidence beyond the success list. All the original Lab properties and plain Markdown content continue to work.

A LITTLE CLEARER?

Take a moment to explain the idea in your own words.

Progress is saved in this browser.

The Component Workshop

Course overview ↗