Container Issues
Debug Docker and Kubernetes container problems.
Docker Debugging
Container Not Starting
# View logs
docker logs container_name
docker logs --tail 100 container_name
# Inspect container
docker inspect container_name
# Check exit code
docker inspect container_name --format='{{.State.ExitCode}}'
# See last run
docker ps -aContainer Crashes
# Follow logs
docker logs -f container_name
# Events
docker events
# Stats
docker stats container_name
# Exec into running container
docker exec -it container_name /bin/shNetwork Issues
# Inspect networks
docker network ls
docker network inspect bridge
# Container networking
docker inspect container_name | grep -A 20 NetworkSettings
# Test from inside container
docker exec container_name ping other_container
docker exec container_name curl http://service:8080Resource Issues
# Container resource usage
docker stats
# Check limits
docker inspect container_name | grep -A 10 HostConfig
# View system resources
docker system dfKubernetes Debugging
Pod Not Starting
# Pod status
kubectl get pods
kubectl describe pod pod_name
# Events
kubectl get events --sort-by=.lastTimestamp
# Logs
kubectl logs pod_name
kubectl logs pod_name --previous # Previous instanceCommon Pod States
| State | Meaning | Action |
|---|---|---|
| Pending | Waiting for resources | Check resources, node |
| ContainerCreating | Pulling image | Check image, registry |
| CrashLoopBackOff | Keeps crashing | Check logs |
| ImagePullBackOff | Can't pull image | Check image name, auth |
| Error | Container error | Check logs |
Debug Commands
# Exec into pod
kubectl exec -it pod_name -- /bin/sh
# Copy files
kubectl cp pod_name:/path/file ./file
# Port forward
kubectl port-forward pod_name 8080:80
# Run debug container
kubectl run debug --rm -it --image=busybox -- /bin/shNetwork Debugging
# Test connectivity
kubectl exec pod_name -- ping service_name
kubectl exec pod_name -- curl http://service:port
# DNS
kubectl exec pod_name -- nslookup kubernetes
# Service endpoints
kubectl get endpoints service_nameResource Issues
# Resource usage
kubectl top pods
kubectl top nodes
# Describe for resource limits
kubectl describe pod pod_name | grep -A 5 Limits
# Check resource quotas
kubectl describe resourcequotaImage Issues
# Check image
docker images | grep myimage
# Pull manually
docker pull myimage:tag
# Inspect image
docker image inspect myimage:tag
# Build with no cache
docker build --no-cache -t myimage .Volume/Storage Issues
Docker
# List volumes
docker volume ls
# Inspect volume
docker volume inspect volume_name
# Check mounts
docker inspect container_name | grep -A 10 MountsKubernetes
# PVC status
kubectl get pvc
# Describe PVC
kubectl describe pvc pvc_name
# Check storage class
kubectl get storageclassQuick Fixes
# Docker: Restart container
docker restart container_name
# Docker: Recreate container
docker-compose up -d --force-recreate service
# K8s: Delete pod (will recreate)
kubectl delete pod pod_name
# K8s: Rollout restart
kubectl rollout restart deployment/app - docker
- kubernetes
- container
- troubleshooting
- debugging