Objective
Document the difference between restart: always and restart: unless-stopped after a host reboot.
Tasks
Task 1: Set up containers with each policy
docker run -d --name reboot-always --restart always nginx:1.27
docker run -d --name reboot-unless --restart unless-stopped nginx:1.27
docker run -d --name reboot-onfail --restart on-failure nginx:1.27
docker run -d --name reboot-no --restart no nginx:1.27
docker stop reboot-unless # Mark as "manually stopped"
docker ps --format '{{.Names}}\t{{.Status}}'
Task 2: Predict
Before rebooting, predict what each container will look like after the host comes back.
Task 3: Reboot
sudo reboot
Task 4: Observe
After reboot:
docker ps -a --format '{{.Names}}\t{{.Status}}\t{{.Image}}'
Expected:
| Container | Restart policy | Status after reboot |
|---|---|---|
| reboot-always | always | Running |
| reboot-unless | unless-stopped | Exited (manually stopped) |
| reboot-onfail | on-failure | Running (only if exited non-zero pre-reboot) |
| reboot-no | no | Exited (or never started) |
Task 5: Cleanup
docker rm -f reboot-always reboot-unless reboot-onfail reboot-no