Container Debug
by @gitgoodordietrying
Debug running Docker containers and Compose services. Use when inspecting container logs, exec-ing into running containers, diagnosing networking issues, checking resource usage, debugging multi-stage builds, troubleshooting health checks, or fixing Compose service dependencies.
clawhub install container-debugπ About This Skill
name: container-debug description: Debug running Docker containers and Compose services. Use when inspecting container logs, exec-ing into running containers, diagnosing networking issues, checking resource usage, debugging multi-stage builds, troubleshooting health checks, or fixing Compose service dependencies. metadata: {"clawdbot":{"emoji":"π³","requires":{"bins":["docker"]},"os":["linux","darwin","win32"]}}
Container Debug
Debug running Docker containers and Compose services. Covers logs, exec, networking, resource inspection, multi-stage builds, health checks, and common failure patterns.
When to Use
Container Logs
View and filter logs
# Last 100 lines
docker logs --tail 100 my-containerFollow (stream) logs
docker logs -f my-containerFollow with timestamps
docker logs -f -t my-containerLogs since a time
docker logs --since 30m my-container
docker logs --since "2026-02-03T10:00:00" my-containerLogs between times
docker logs --since 1h --until 30m my-containerCompose: logs for all services
docker compose logs -fCompose: logs for specific service
docker compose logs -f api dbRedirect logs to file for analysis
docker logs my-container > container.log 2>&1Separate stdout and stderr
docker logs my-container > stdout.log 2> stderr.log
Inspect log driver
# Check what log driver a container uses
docker inspect --format='{{.HostConfig.LogConfig.Type}}' my-containerIf json-file driver, find the actual log file
docker inspect --format='{{.LogPath}}' my-containerCheck log file size
ls -lh $(docker inspect --format='{{.LogPath}}' my-container)
Exec Into Containers
Interactive shell
# Bash (most common)
docker exec -it my-container bashIf bash isn't available (Alpine, distroless)
docker exec -it my-container shAs root (even if container runs as non-root user)
docker exec -u root -it my-container bashWith specific environment variables
docker exec -e DEBUG=1 -it my-container bashRun a single command (no interactive shell)
docker exec my-container cat /etc/os-release
docker exec my-container ls -la /app/
docker exec my-container env
Debug a crashed container
# Container exited? Check exit code
docker inspect --format='{{.State.ExitCode}}' my-container
docker inspect --format='{{.State.Error}}' my-containerCommon exit codes:
0 = clean exit
1 = application error
137 = killed (OOM or docker kill) β 128 + signal 9
139 = segfault β 128 + signal 11
143 = terminated (SIGTERM) β 128 + signal 15
Start a stopped container to debug it
docker start -ai my-containerOr override the entrypoint to get a shell
docker run -it --entrypoint sh my-imageCopy files out of a stopped container
docker cp my-container:/app/error.log ./error.log
docker cp my-container:/etc/nginx/nginx.conf ./nginx.conf
Debug without a shell (distroless / scratch images)
# Use docker cp to extract files
docker cp my-container:/app/config.json ./Use nsenter to get a shell in the container's namespace (Linux)
PID=$(docker inspect --format='{{.State.Pid}}' my-container)
nsenter -t $PID -m -u -i -n -p -- /bin/shAttach a debug container to the same namespace
docker run -it --pid=container:my-container --net=container:my-container busybox shDocker Desktop: use debug extension
docker debug my-container
Networking
Inspect container networking
# Show container IP address
docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' my-containerShow all network details
docker inspect -f '{{json .NetworkSettings.Networks}}' my-container | jqList all networks
docker network lsInspect a network (see all connected containers)
docker network inspect bridge
docker network inspect my-compose-networkShow port mappings
docker port my-container
Test connectivity between containers
# From inside container A, reach container B
docker exec container-a ping container-b
docker exec container-a curl http://container-b:8080/healthDNS resolution inside container
docker exec my-container nslookup db
docker exec my-container cat /etc/resolv.conf
docker exec my-container cat /etc/hostsTest if port is reachable
docker exec my-container nc -zv db 5432
docker exec my-container wget -qO- http://api:3000/healthIf curl/ping not available in container, install or use a debug container:
docker run --rm --network container:my-container curlimages/curl curl -s http://localhost:8080
Common networking issues
# "Connection refused" between containers
1. Check the app binds to 0.0.0.0, not 127.0.0.1
docker exec my-container netstat -tlnp
If listening on 127.0.0.1 β fix the app config
2. Check containers are on the same network
docker inspect -f '{{json .NetworkSettings.Networks}}' container-a | jq 'keys'
docker inspect -f '{{json .NetworkSettings.Networks}}' container-b | jq 'keys'3. Check published ports vs exposed ports
EXPOSE only documents, it doesn't publish
Use -p host:container to publish
"Name not found" β DNS not resolving container names
Container names resolve only on user-defined networks, NOT the default bridge
docker network create my-net
docker run --network my-net --name api my-api-image
docker run --network my-net --name db postgres
Now "api" and "db" resolve to each other
Capture network traffic
# tcpdump inside a container
docker exec my-container tcpdump -i eth0 -n port 8080If tcpdump not available, use a sidecar
docker run --rm --net=container:my-container nicolaka/netshoot tcpdump -i eth0 -nnetshoot has: tcpdump, curl, nslookup, netstat, iperf, etc.
docker run --rm --net=container:my-container nicolaka/netshoot bash
Resource Usage
Real-time stats
# All containers
docker statsSpecific containers
docker stats api db redisOne-shot (no streaming)
docker stats --no-streamFormatted output
docker stats --format "table {{.Name}}\t{{.CPUPerc}}\t{{.MemUsage}}\t{{.NetIO}}"
Memory investigation
# Check memory limit
docker inspect --format='{{.HostConfig.Memory}}' my-container
0 means unlimited
Check if container was OOM-killed
docker inspect --format='{{.State.OOMKilled}}' my-containerMemory usage breakdown (Linux cgroups)
docker exec my-container cat /sys/fs/cgroup/memory.current 2>/dev/null || \
docker exec my-container cat /sys/fs/cgroup/memory/memory.usage_in_bytesProcess memory inside container
docker exec my-container ps aux --sort=-%mem | head -10
docker exec my-container top -bn1
Disk usage
# Overall Docker disk usage
docker system df
docker system df -vContainer filesystem size
docker inspect --format='{{.SizeRw}}' my-containerFind large files inside container
docker exec my-container du -sh /* 2>/dev/null | sort -rh | head -10
docker exec my-container find /tmp -size +10M -type fCheck for log file bloat
docker exec my-container ls -lh /var/log/
Dockerfile Debugging
Multi-stage build debugging
# Build up to a specific stage
docker build --target builder -t my-app:builder .Inspect what's in the builder stage
docker run --rm -it my-app:builder sh
docker run --rm my-app:builder ls -la /app/
docker run --rm my-app:builder cat /app/package.jsonCheck which files made it to the final image
docker run --rm my-image ls -laR /app/Build with no cache (fresh build)
docker build --no-cache -t my-app .Build with progress output
docker build --progress=plain -t my-app .
Image inspection
# Show image layers (size of each)
docker history my-image
docker history --no-trunc my-imageInspect image config (entrypoint, cmd, env, ports)
docker inspect my-image | jq '.[0].Config | {Cmd, Entrypoint, Env, ExposedPorts, WorkingDir}'Compare two images
docker history image-a --format "{{.Size}}\t{{.CreatedBy}}" > layers-a.txt
docker history image-b --format "{{.Size}}\t{{.CreatedBy}}" > layers-b.txt
diff layers-a.txt layers-b.txtFind what changed between builds
docker diff my-container
A = added, C = changed, D = deleted
Health Checks
Define and debug health checks
# In Dockerfile
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
CMD curl -f http://localhost:8080/health || exit 1
# Check health status
docker inspect --format='{{.State.Health.Status}}' my-container
"healthy", "unhealthy", or "starting"
See health check log (last 5 results)
docker inspect --format='{{json .State.Health}}' my-container | jqRun health check manually
docker exec my-container curl -f http://localhost:8080/healthOverride health check at run time
docker run --health-cmd "curl -f http://localhost:8080/health || exit 1" \
--health-interval 10s my-imageDisable health check
docker run --no-healthcheck my-image
Docker Compose Debugging
Service startup issues
# Check service status
docker compose psSee why a service failed
docker compose logs failed-serviceStart with verbose output
docker compose up --build 2>&1 | tee compose.logStart a single service (with dependencies)
docker compose up dbStart without dependencies
docker compose up --no-deps apiRecreate containers from scratch
docker compose up --force-recreate --buildCheck effective config (after variable substitution)
docker compose config
Service dependency and startup order
# docker-compose.yml
services:
api:
depends_on:
db:
condition: service_healthy
redis:
condition: service_started db:
image: postgres:16
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 5s
timeout: 5s
retries: 5
redis:
image: redis:7
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 5s
timeout: 5s
retries: 5
# Wait for a service to be healthy before running commands
docker compose up -d db
docker compose exec db pg_isready # Polls until ready
docker compose up -d api
Cleanup
# Remove stopped containers
docker container pruneRemove unused images
docker image pruneRemove everything unused (containers, images, networks, volumes)
docker system prune -aRemove volumes too (WARNING: deletes data)
docker system prune -a --volumesRemove dangling build cache
docker builder prune
Tips
docker logs -f is the first thing to check. Most container failures are visible in the logs.0.0.0.0, not 127.0.0.1. Localhost inside a container is isolated.bridge. Always create a custom network for multi-container setups.docker exec only works on running containers. For crashed containers, use docker cp to extract logs or override the entrypoint with docker run --entrypoint sh.nicolaka/netshoot is the Swiss Army knife for container networking. It has every networking tool pre-installed.--progress=plain during builds shows full command output, which is essential for debugging build failures.start-period prevent false unhealthy status during slow application startup.β‘ When to Use
π Tips & Best Practices
docker logs -f is the first thing to check. Most container failures are visible in the logs.0.0.0.0, not 127.0.0.1. Localhost inside a container is isolated.bridge. Always create a custom network for multi-container setups.docker exec only works on running containers. For crashed containers, use docker cp to extract logs or override the entrypoint with docker run --entrypoint sh.nicolaka/netshoot is the Swiss Army knife for container networking. It has every networking tool pre-installed.--progress=plain during builds shows full command output, which is essential for debugging build failures.start-period prevent false unhealthy status during slow application startup.