🆘 FAQ & Troubleshooting
Issue 1: Container Exits Immediately After Starting
bash
# Step 1: Check the exit code
docker inspect --format='{{.State.ExitCode}}' myapp
# Step 2: Check the logs
docker logs myapp
# Common causes and solutions:
# ExitCode 0 — App finished and exited (likely a misconfigured CMD)
# ExitCode 1 — App error, check the logs
# ExitCode 126 — Command not permitted, check if chmod +x is needed
# ExitCode 127 — Command not found, check PATH
# ExitCode 137 — OOM killed, increase --memory limit
# ExitCode 139 — Segmentation fault, check application code
# Debug with interactive mode
docker run -it --entrypoint /bin/bash myapp
# Manually run the startup command inside to see the errorIssue 2: Container Has No Network Access
bash
# Check if container DNS is working
docker exec myapp cat /etc/resolv.conf
# Test if the container can resolve domain names
docker exec myapp nslookup google.com
# Check container network mode
docker inspect --format='{{.HostConfig.NetworkMode}}' myapp
# Reset Docker networks
docker network prune
# If host can't reach container IP in bridge mode — check IP forwarding
sysctl net.ipv4.ip_forward
# Should be 1; if it's 0:
sysctl -w net.ipv4.ip_forward=1
echo "net.ipv4.ip_forward=1" >> /etc/sysctl.confIssue 3: Docker Eats Up All Disk Space
bash
# Check Docker disk usage
docker system df -v
# One-click cleanup (removes stopped containers, unused images, unused networks)
docker system prune -a -f
# Clean up all unused volumes (⚠️ will delete data!)
docker volume prune -f
# Clean up build cache
docker builder prune -a -f
# Configure log rotation (prevent logs from filling disk — the most common cause!)
# /etc/docker/daemon.json
{
"log-driver": "json-file",
"log-opts": {
"max-size": "10m",
"max-file": "3"
}
}
systemctl restart dockerIssue 4: docker pull Is Slow / Times Out
bash
# Configure mirror acceleration (essential for users in China)
cat > /etc/docker/daemon.json << 'EOF'
{
"registry-mirrors": [
"https://mirror.ccs.tencentyun.com",
"https://docker.1ms.run"
]
}
EOF
systemctl restart docker
# Verify it's in effect
docker info | grep -A 5 "Registry Mirrors"
# If your company has a private registry
docker login registry.company.com
docker pull registry.company.com/myapp:latest
# Manually specify platform for pulling (fixes multi-arch issues)
docker pull --platform linux/amd64 myapp:latest