# Demonstration: One File, Two Containers, One Network — Automatically ## OBSERVE ```yaml services: web: image: nginx:alpine ports: - "8080:80" cache: image: redis:alpine ``` ## HYPOTHESIS Predict: without running `docker network create` yourself, will `web` be able to reach `cache` by name after `docker compose up`? ## INSPECT ``` $ docker compose up -d $ docker compose exec web sh -c "wget -qO- http://cache:6379/ 2>&1 | head -1" ``` (Redis doesn't speak HTTP, so this specific request looks odd, but the connection ITSELF succeeding or failing tells you whether name resolution and network reachability work — a `Connection refused` here would mean it REACHED `cache` but Redis rejected the protocol mismatch, which is actually proof the network worked.) ## CHANGE ``` $ docker compose ps NAME IMAGE STATUS web-1 nginx:alpine Up cache-1 redis:alpine Up $ docker network ls | grep compose xyz123 myproject_default bridge ``` Compose created a network automatically, named after the project directory, with no manual step. ## VERIFY ``` $ docker compose down $ docker network ls | grep compose (nothing) ``` `docker compose down` cleaned up EVERYTHING Compose created — containers AND the network — in one command. ## Instructor Notes **Demo goal:** Show the automatic networking as a real, observable fact (a real network exists, named and scoped to the project) rather than an assumed convenience. **Approximate timing:** 8 minutes live. **Common mistake to watch for:** forgetting `docker compose down` and accumulating orphaned networks/containers across multiple exercises — a good habit to reinforce explicitly.