4/4
Debugging & Troubleshooting
+15 XP on completion
#Debugging & Troubleshooting
After this lesson you'll know:
- how to find out why a container won't start
- how to look inside a running container
- the most common errors and their solutions
#Container won't start?
# 1. Check the logs
docker logs container-name
# 2. Check status
docker ps -a # Maybe it's running but crashing immediately?
# 3. Inspect for details
docker inspect container-name
# Shows: entry point, env vars, mounts, network...
#Looking inside a container
# If it's running: open a shell
docker exec -it container-name sh
docker exec -it container-name bash # if sh isn't enough
# For debugging: start a temporary container
docker run -it --rm alpine sh
#Port Conflicts
# Error: "port is already allocated"
# Solution: Find out what is using it
lsof -i :8080
docker ps # Maybe another container?
# Alternatives:
docker run -p 8081:80 nginx
# Or stop the old container
docker stop old-container
#Network Debugging
# Test if a container has internet access
docker run alpine ping -c 1 google.com
# DNS issues?
docker run --dns 8.8.8.8 alpine ping google.com
# Inspect a network
docker network inspect bridge
#Image Size Check
docker images --format "table {{.Repository}} {{.Size}} {{.Tag}}"
docker system df
#โ Try it out
- Start a container that crashes immediately (
docker run alpine invalid-command). Usedocker logsto find out why - Start a running container and open a shell with
docker exec -it. Look around:cat /etc/os-release,ps aux,env - Simulate a port conflict: start two containers on the same host port. What does Docker say?
#๐ Summary
- docker logs = first place to check when something goes wrong
- docker exec -it container-name sh opens a shell inside the container
- docker inspect gives all the details about a container
Docker-Pro Challenge
Test your knowledge with a quick quiz!
3 questions ยท +100 XP