Container Debug with Ephemeral Containers
Intermediate10 minTrending
Debug running containers by attaching an ephemeral debug shell or inspecting container internals without modifying the original image.
Prerequisites
- -Docker installed
- -A running container to debug
Steps
1
List running containers
Identify the container you want to debug.
$ docker ps --format 'table {{.ID}}\t{{.Names}}\t{{.Status}}\t{{.Image}}'
2
Exec into a running container
Open an interactive shell inside a running container.
$ docker exec -it <container-name> /bin/sh
Use /bin/sh if /bin/bash is not available (common in Alpine-based images).
3
Run a debug sidecar with full tools
Attach a debug container that shares the network and PID namespace of the target container.
$ docker run -it --rm --pid=container:<container-name> --net=container:<container-name> nicolaka/netshoot
nicolaka/netshoot includes curl, dig, nslookup, tcpdump, iptables, and many more network tools.
4
Copy files from a container for inspection
Extract files from a container to your local machine for analysis.
$ docker cp <container-name>:/app/logs/ ./debug-logs/
5
View container resource usage in real time
Monitor CPU, memory, and network I/O of running containers.
$ docker stats --format 'table {{.Name}}\t{{.CPUPerc}}\t{{.MemUsage}}\t{{.NetIO}}'
Full Script
FAQ
Discussion
Loading comments...