Two slots, one of them live
The simplest fix for the stop-start gap: never take down your only copy of the app. The Titik Terang lab uses two names, blue and green. Both are containers from the same image, on different host ports.
One thing matters from the start: this is not double capacity. Only one slot receives traffic at any moment. The other is idle — deliberately empty, waiting for the next deploy.
Ports that stay on loopback
- The app inside the container listens on
:3000. - The blue slot maps to
127.0.0.1:18080. - The green slot maps to
127.0.0.1:18081. - Caddy listens on
:8080and picks one of those two ports.
Mapping to 127.0.0.1 keeps the slots local. Public readers only ever see Caddy.
- Blue is live on :18080. Green sits idle on :18081.
- Green can become live. Only one slot receives traffic.
state.json
This small file remembers which slot is live and which version can be rolled back. The playbook reads it before it works — it is the single source of truth. Change the live key in the explainer below to see which idle slot it would pick.
Quick recap
- Two slots means one live and one idle; capacity stays at one.
- Slots only listen on
127.0.0.1— the public may only ever find Caddy. state.jsonis the source of truth for which slot is live.- Bonus: the old slot stays up briefly after a switch — that is the capital for rollback in chapter 10.