Lab: Docker Compose basics
Run two containers from public images with one compose.yaml. No Dockerfile, no application code. The goal is to see how Compose starts a stack, maps ports, and names services on the same network.
Lab objective
- Use
docker compose upanddown. - Reach each service from your host with
curl. - Run
docker compose psanddocker compose logs.
Prerequisites
- Docker with Compose v2 (
docker compose).
Hands on
1. Project directory
mkdir -p peachycloudsecurity-compose-lab && cd peachycloudsecurity-compose-lab
2. Compose file
cat <<'EOF' > compose.yaml
services:
web:
image: nginx:1.27-alpine
ports:
- "8080:80"
whoami:
image: traefik/whoami:v1.10.2
ports:
- "8081:80"
EOF
web serves the default nginx page. whoami returns a short text response (container hostname and request headers) on port 80 inside the container, mapped to 8081 on your host.
3. Start the stack
docker compose up -d
docker compose ps
4. Call both services
curl -sS http://127.0.0.1:8080/ | head -n 3
curl -sS http://127.0.0.1:8081/ | head -n 5
5. Logs and stop
docker compose logs --tail=10 web
docker compose logs --tail=10 whoami
docker compose down
Clean up
cd .. && rm -rf peachycloudsecurity-compose-lab
Summary
- Compose pulled two images and wired a private network between services (you can add more later).
portspublishes containers to your laptop; service names such aswebare DNS names inside the Compose network.- The same multi-service idea appears on larger platforms that schedule containers for you.
- Next step: Image Build and Delivery, then Theory: Registry and image lifecycle and Lab: Slim Python images.