3/3
Docker Context & Multi-Host
+20 XP on completion
#Docker Context & Multi-Host
After this lesson you'll know:
- managing multiple servers with one command
- docker context for staging/production
- monitoring multiple hosts
#Managing Multiple Servers
# Context for Staging
docker context create staging --docker "host=ssh://[email protected]"
# Context for Production
docker context create production --docker "host=ssh://[email protected]"
# Switching
docker use context staging
docker compose up -d
docker use context production
docker compose up -d
#Monitoring Multiple Hosts
# Check status on all hosts
for ctx in staging production; do
docker use context $ctx
echo "=== $ctx ==="
docker ps --format "table {{.Names}} {{.Status}}"
done
#Avoiding Accidents
# Show the current context
docker context show
# โ "default" or "staging" or "production"
# Always check before making changes:
docker ps # Is this local or remote?
#โ Try it out
- Create two contexts:
devandprod(even if they point to the same server, just for practice). Switch between them withdocker use context - Write a small script that runs
docker pson all contexts and shows the results
#๐ Summary
- docker context create creates one context per server
- docker use context switches the target server
- docker context show displays the current context โ always check!
SSH Tunnel Challenge
Test your knowledge with a quick quiz!
3 questions ยท +40 XP