| name | debug:docker |
| description | Debug Docker containers, images, and infrastructure with systematic diagnostic techniques. This skill provides comprehensive guidance for troubleshooting container exit codes, OOM kills, image build failures, networking issues, volume mount problems, and permission errors. Covers four-phase debugging methodology from quick assessment to deep analysis, essential Docker commands, debug container techniques for minimal images, and platform-specific troubleshooting for Windows, Mac, and Linux. |
Docker Debugging Guide
This guide provides a systematic approach to debugging Docker containers, images, networks, and volumes. Follow the four-phase methodology for efficient problem resolution.
The Four Phases of Docker Debugging
Phase 1: Quick Assessment (30 seconds)
Get immediate context about the issue.
docker ps -a
docker logs --tail 50 <container>
docker inspect <container> --format='{{.State.ExitCode}}'
docker inspect <container> --format='{{.State.Health.Status}}'
Phase 2: Log Analysis (2-5 minutes)
Deep dive into container logs and events.
docker logs -f <container>
docker logs --timestamps <container>
docker logs --since 30m <container>
docker events --since 1h
journalctl -u docker.service --since "1 hour ago"
Phase 3: Interactive Investigation (5-15 minutes)
Get hands-on access to the container environment.
docker exec -it <container> /bin/sh
docker exec -it <container> /bin/bash
docker exec <container> cat /etc/hosts
docker exec <container> env
docker debug <container>
docker inspect <container>
docker network inspect <network>
Phase 4: Deep Analysis (15+ minutes)
Comprehensive investigation for complex issues.
docker stats <container>
docker system df -v
docker history <image>
docker export <container> -o container.tar
docker inspect <container> | jq '.'
Common Error Patterns and Solutions
Exit Codes
| Exit Code | Meaning | Common Causes | Solution |
|---|
| 0 | Success | Normal termination | No action needed |
| 1 | General error | Application error, missing file | Check logs, verify files exist |
| 126 | Permission problem | Cannot execute command | Check file permissions, add execute bit |
| 127 | Command not found | Missing binary or PATH issue | Verify command exists in image |
| 137 | SIGKILL (OOM) | Out of memory | Increase memory limit, optimize app |
| 139 | SIGSEGV | Segmentation fault | Debug application code |
| 143 | SIGTERM | Graceful shutdown | Normal behavior during stop |
| 255 | Exit status out of range | Various | Check application error handling |
OOM Killed Containers (Exit Code 137)
docker inspect <container> --format='{{.State.OOMKilled}}'
docker inspect <container> --format='{{.HostConfig.Memory}}'
docker run -m 2g --memory-swap 4g <image>
docker stats --format "table {{.Name}}\t{{.MemUsage}}\t{{.MemPerc}}"
Image Build Failures
docker build --progress=plain -t <image> .
docker build --no-cache -t <image> .
docker build --target <stage-name> -t <image> .
docker builder prune --dry-run
docker run -it <last-successful-layer-id> /bin/sh
Common Build Issues:
COPY failed: file not found - Check paths are relative to build context
RUN failed - Check command syntax, ensure dependencies are installed
Permission denied - Add chmod or run as appropriate user
Networking Issues
docker network ls
docker network inspect <network>
docker inspect <container> --format='{{json .NetworkSettings.Networks}}'
docker exec <container1> ping <container2>
docker exec <container> nslookup <hostname>
docker port <container>
docker run --rm --network=<network> nicolaka/netshoot ping <target>
Common Network Issues:
- Containers on different networks cannot communicate
- Port already in use:
lsof -i :<port> to find conflicting process
- DNS resolution fails: Check Docker DNS settings
Volume Mount Problems
docker volume ls
docker volume inspect <volume>
docker inspect <container> --format='{{json .Mounts}}'
ls -la /path/to/host/directory
docker exec <container> ls -la /mount/path
docker run --rm -v /host/path:/container/path alpine ls -la /container/path
Common Volume Issues:
Permission denied - Check UID/GID mapping, use :z or :Z for SELinux
- Path not found - Ensure host path exists before mounting
- Windows paths - Use forward slashes or escaped backslashes
Permission Denied Errors
sudo usermod -aG docker $USER
newgrp docker
ls -la /var/run/docker.sock
docker run --user $(id -u):$(id -g) <image>
RUN chown -R appuser:appuser /app
USER appuser
Container Exits Immediately
docker inspect <container> --format='{{.Config.Cmd}}'
docker inspect <container> --format='{{.Config.Entrypoint}}'
docker run -d <image> tail -f /dev/null
docker run -d <image> sleep infinity
docker run -it --entrypoint /bin/sh <image>
Docker Desktop Won't Start
Windows:
- Enable Hyper-V:
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All
- Enable WSL2:
wsl --install
- Check virtualization in BIOS (VT-x/AMD-V)
- Temporarily disable antivirus
Mac:
- Check available disk space
- Reset Docker Desktop: Delete
~/Library/Group\ Containers/group.com.docker/
- Reinstall Docker Desktop
Linux:
- Check Docker daemon:
sudo systemctl status docker
- View daemon logs:
journalctl -u docker.service
Debugging Tools Reference
Essential Commands
docker ps -a
docker logs <container>
docker logs -f --tail 100 <container>
docker exec -it <container> sh
docker inspect <container>
docker top <container>
docker images
docker history <image>
docker inspect <image>
docker system df
docker system events
docker system info
docker system prune
docker network ls
docker network inspect <network>
docker volume ls
docker volume inspect <volume>
Advanced Debugging
docker debug <container>
docker exec <container> ps aux
docker exec <container> top
docker exec <container> netstat -tlnp
docker exec <container> ss -tlnp
docker exec <container> curl -v <url>
docker diff <container>
docker cp <container>:/path ./local
docker cp ./local <container>:/path
docker stats
docker stats --no-stream
Debug Container Image
For minimal images without debugging tools, use a sidecar approach:
docker run -it --network container:<target> nicolaka/netshoot
docker run -it --pid container:<target> busybox
Quick Reference Commands
docker ps -a
docker logs --tail 100 -f <container>
docker exec -it <container> sh
docker inspect <container>
docker stats
docker system df
docker events
docker network ls
docker network inspect <network>
docker exec <container> ping <host>
docker system prune -af
docker volume prune
docker builder prune
Troubleshooting Checklist
Sources