
Docker Troubleshooting
- 11 installs
- 2 repo stars
- Updated July 29, 2026
- full-statck-skills/docker-skills
Debug Docker problems like container startup failures, OOM kills, disk exhaustion, network issues, and daemon errors using a systematic diagnostic framework.
About
Guides systematic debugging of Docker issues including startup failures, OOM, disk exhaustion, and network problems. A developer uses it when a container crashes or Docker misbehaves.
- Diagnostic framework: state, logs, resources, exit codes, interactive debug
- Covers startup failures, OOM, disk exhaustion, network connectivity, and daemon problems
Docker Troubleshooting by the numbers
- 11 all-time installs (skills.sh)
- Ranked #418 of 596 Debugging skills by installs in the Skillselion catalog
- Data as of Jul 30, 2026 (Skillselion catalog sync)
npx skills add https://github.com/full-statck-skills/docker-skills --skill docker-troubleshootingAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 11 |
|---|---|
| repo stars | ★ 2 |
| Last updated | July 29, 2026 |
| Repository | full-statck-skills/docker-skills ↗ |
What it does
Debug Docker problems like container startup failures, OOM kills, disk exhaustion, network issues, and daemon errors using a systematic diagnostic framework.
Files
Docker Troubleshooting — 问题排查与调试
Systematic approach to diagnosing and resolving common Docker issues.
When to Use
ALWAYS use this skill when the user mentions:
- "docker 排查", "docker debug", "容器问题"
- "容器启动失败", "exit code", "crash"
- "OOM", "磁盘满", "disk full"
- "网络不通", "network issues"
- "docker daemon", "daemon not running"
Diagnostic Framework
1. Check container state → docker ps -a, docker inspect
2. Check logs → docker logs --tail 100
3. Check resources → docker stats, docker system df
4. Check exit code → docker inspect --format='{{.State.ExitCode}}'
5. Interactive debug → docker run --rm -it image shContainer Startup Failure
Exit Code Reference
| Code | Meaning | Action |
|---|---|---|
| 0 | Success | — |
| 1 | Application error | Check docker logs |
| 125 | Docker daemon error | Check daemon status |
| 126 | Command cannot execute | Check permissions |
| 127 | Command not found | Check CMD/ENTRYPOINT path |
| 137 | SIGKILL (OOM or docker kill) | Check memory limits |
| 139 | SIGSEGV (segfault) | Application bug |
| 143 | SIGTERM (graceful stop) | Health check timeout? |
# Quick diagnosis
docker ps -a | grep Exited
docker inspect --format='{{.State.ExitCode}} {{.State.Error}}' container
docker logs containerDisk Space Exhaustion
# Check disk usage
docker system df
# What's using space?
docker system df -v # Verbose breakdown
# Clean up
docker system prune -a # Remove all unused: images, containers, volumes, networks
docker image prune -a # Unused images only
docker volume prune # Unused volumes only
# Log rotation (prevent future issues)
docker run --log-opt max-size=10m --log-opt max-file=3 myappOOM (Out of Memory)
# Check if container was OOM-killed
docker inspect --format='{{.State.OOMKilled}}' container
# Check memory usage
docker stats --no-stream
# Solution: increase memory limit
docker update --memory=1g --memory-swap=1g containerNetwork Connectivity
# Check network configuration
docker network inspect bridge
docker exec container ip addr show
docker exec container ping other-container
# DNS check
docker exec container nslookup other-container
docker exec container cat /etc/resolv.conf
# Host networking check
iptables -t nat -L DOCKER -n # Port forwarding rulesPermission Issues
# Bind mount permission denied
# Solution 1: Match UID
docker run -u $(id -u):$(id -g) -v $PWD:/app myapp
# Solution 2: Fix permissions in entrypoint
# In entrypoint script: chown -R appuser:appgroup /data
# Docker socket permission
sudo usermod -aG docker $USER # Add user to docker group
newgrp docker # Refresh group (or re-login)Workflow — 排查流程
Step 1: 查看状态: docker ps -a → 确认退出码和 OOMKilled Step 2: 查看日志: docker logs --tail 100 <container> 获取错误信息 Step 3: 深入检查: docker inspect → 检查网络/挂载/资源限制 Step 4: 交互调试: docker run -it --rm --entrypoint sh <image> 进入排查 Step 5: 资源排查: docker stats + docker system df 检查 CPU/内存/磁盘
Gotchas — Common Pitfalls
- `docker system prune` is destructive: Removes ALL unused objects. Don't run blindly in production. → Recovery: Use
docker system dffirst to preview; add--filter "until=24h"for safe cleanup; never runprune -awithout confirmation. - Logs fill disk silently: JSON-file driver has NO rotation by default. A noisy app can fill the disk in hours. → Recovery:
docker run --log-opt max-size=10m --log-opt max-file=3 app; existing:truncate -s 0 $(docker inspect -f '{{.LogPath}}' myapp). - OOMKilled=TRUE but no error in logs: SIGKILL can't be logged. → Recovery: Check
docker inspect -f '{{.State.OOMKilled}}' myapp; increase memory:docker update --memory 512m myapp. - Exited (0) but service not working: Application started but crashed after health check passed. → Recovery:
docker logs --tail 100 myapp; check if app listens on 0.0.0.0 (not 127.0.0.1); verify withdocker exec myapp netstat -tlnp.
Boundary — 能力边界(适用与不适用场景)
| 分类 | 场景 | 说明 |
|---|---|---|
| ✅ 能做 | 容器启动失败排查 | 退出码分析 + docker logs + inspect |
| ✅ 能做 | 磁盘/日志/资源问题 | docker system df + prune + log rotation |
| ✅ 能做 | OOM/CPU 排查 | docker stats + --memory 限制 + OOMKilled |
| ⚠️ 需条件 | 网络包级分析 | 需 tcpdump/Wireshark + 网络知识 |
| ⚠️ 需条件 | 内核级问题 | 需 Linux 内核调试技能 |
| ❌ 超范围 | 应用代码 bug 修复 | 开发者修复代码 |
| ❌ 超范围 | 生产环境部署 | 使用 docker-production |
| ❌ 超范围 | 安全漏洞修复 | 使用 docker-security + docker-scout |
When NOT to Use This Skill
| ❌ Skip | ✅ Use Instead |
|---|---|
| Setting up production | docker-production |
| Security issues | docker-security |
| Performance tuning | docker-run (resource limits) |
| Docker basics | docker-basics |
Security & Stability
docker execinto production containers can expose sensitive data. Prefer log-based debugging.docker system prune -aremoves ALL unused images and volumes — use with caution in production.- Inspecting containers with
--privilegeddebug tools can bypass security controls. - Never expose Docker socket (
/var/run/docker.sock) to containers for debugging — it grants root access. - Rotate debug logs — they may contain sensitive information. Use log drivers with TTL.
📚 官方文档参考
| 文档 | 地址 |
|---|---|
| Docker 引擎故障排查 | https://docs.docker.com/engine/troubleshoot/ |
| docker logs 命令 | https://docs.docker.com/reference/cli/docker/container/logs/ |
| docker inspect | https://docs.docker.com/reference/cli/docker/inspect/ |
| Docker CLI 参考 | https://docs.docker.com/reference/cli/docker/ |
| 守护进程配置 | https://docs.docker.com/reference/cli/dockerd/ |
| 常见问题 FAQ | https://docs.docker.com/faq/ |
🧭 Docker Skills Journey
📍 You are here: `docker-troubleshooting` — 问题排查
← Previous: docker-production
Debug a crashing container
# Scenario: Container exits immediately after starting
# 1. Check status
docker ps -a
# STATUS: Exited (1) 2 seconds ago
# 2. Get exit code
docker inspect --format='{{.State.ExitCode}}' myapp
# → 1 (application error)
# 3. View logs (even for stopped containers!)
docker logs myapp
# → Error: Cannot connect to database
# 4. Override entrypoint to debug
docker run --rm -it --entrypoint sh myapp
# Now you're inside a shell — debug interactively
# 5. Check resource issues
docker inspect --format='{{.State.OOMKilled}}' myapp
# → false (not OOM this time)
# 6. Try with more memory
docker run --memory=1g myapp容器崩溃调试全过程
症状:容器启动后立即退出
docker run -d --name myapp myapp:latest
docker ps -a | grep myapp
# myapp Exited (1) 2 seconds ago诊断流程
# Step 1: 查看退出码
docker inspect --format='{{.State.ExitCode}}' myapp
# 退出码速查:
# 0 正常退出
# 1 应用错误
# 126 权限不足(CMD 不可执行)
# 127 命令找不到
# 137 SIGKILL(OOM)
# 139 SIGSEGV(段错误)
# 143 SIGTERM(优雅终止)
# Step 2: 查看日志(即使 Exited 也能看到)
docker logs myapp
docker logs --tail 50 myapp
# Step 3: 检查是否 OOM
docker inspect --format='{{.State.OOMKilled}}' myapp
# true → 内存不足,增加 --memory
# Step 4: 覆盖 CMD 进入调试
docker run -it --rm --entrypoint sh myapp:latest
# 进入后手动运行应用,观察输出
# Step 5: 检查文件权限
docker run -it --rm --entrypoint sh myapp:latest
ls -la /app/entrypoint.sh
# 权限不足 → Dockerfile 加 RUN chmod +x
# Step 6: 检查端口绑定
docker inspect --format='{{.NetworkSettings.IPAddress}}' myapp
# 确认应用监听 0.0.0.0 而不是 127.0.0.1常见问题速查
| 症状 | 退出码 | 原因 | 修复 |
|---|---|---|---|
| 秒退 | 127 | 命令找不到 | 检查 ENTRYPOINT/CMD 路径 |
| 秒退 | 1 | 应用崩溃 | docker logs 查堆栈 |
| 30s 后退 | 137 | OOM Kill | --memory=512m 增加限制 |
| 运行但不响应 | 0 | 监听 127.0.0.1 | 改为 0.0.0.0 |
| 启动慢 | - | DNS 超时 | --dns 8.8.8.8 |
Docker Exit Code Reference
| Code | Meaning | Common Cause | Debug Action |
|---|---|---|---|
| 0 | Success | Normal exit | — |
| 1 | Application error | App crashed, wrong config | docker logs |
| 125 | Docker daemon error | docker run failed | Check daemon |
| 126 | Permission denied | CMD/ENTRYPOINT not executable | chmod +x in Dockerfile |
| 127 | Command not found | Wrong path in CMD | docker run --entrypoint sh |
| 137 | SIGKILL | OOM killed or docker kill | Check OOMKilled in inspect; increase memory |
| 139 | SIGSEGV | Segfault (app bug) | Check app code |
| 143 | SIGTERM | Graceful shutdown timeout | Check healthcheck timeout |
磁盘与资源问题排查
磁盘满
# 1. 查看使用量
docker system df
# TYPE TOTAL ACTIVE SIZE RECLAIMABLE
# Images 25 5 12.5GB 8.2GB (65%)
# Containers 8 3 1.2GB 800MB (66%)
# Local Volumes 12 4 3.5GB 2.1GB (60%)
# 2. 详细分析
docker system df -v
# 3. 清理
docker container prune # 删除已停止容器
docker image prune -a # 删除未使用镜像
docker volume prune # 删除未使用卷
docker builder prune # 清理构建缓存
# 4. 安全清理(保留 24h 内的)
docker system prune --filter "until=24h"
# 5. 检查大文件
docker run --rm -v /var/lib/docker:/docker:ro alpine du -sh /docker/*日志膨胀
# 检查日志大小
docker inspect --format='{{.LogPath}}' myapp | xargs ls -lh
# 限制日志大小
docker run -d --log-opt max-size=10m --log-opt max-file=3 myapp
# Compose 中限制
services:
app:
logging:
driver: json-file
options:
max-size: "10m"
max-file: "3"
# 清理日志
truncate -s 0 $(docker inspect --format='{{.LogPath}}' myapp)容器 CPU 100%
# 查看资源使用
docker stats --no-stream
docker top myapp
# 限制 CPU
docker update --cpus 0.5 myapp
# 查看进程
docker exec myapp ps aux --sort=-%cpu | head -5网络耗时排查
# DNS 解析
docker exec myapp nslookup api-service
# 延迟测试
docker exec myapp time curl -s http://api-service:8080/health
# 抓包
docker run --rm --net container:myapp nicolaka/netshoot tcpdump -i eth0 -w /tmp/capture.pcapinode 耗尽
# 检查 inode
df -i /var/lib/docker
# docker 产生的 inode 大户:overlay2 层、小文件多
# 清理:docker system prune -a