Guides
Running Docker Container Debug कैसे करें (logs, exec, inspect)
By Ravindra Bagale, DevOps trainer · LinkedIn · Published: · Last updated:
ps, logs, inspect, exec — फिर restart। कारण fix, recreate, verify।
Friends, never restart first. Chala mitrano — logs, inspect, then exec.
मित्रांनो, आधी restart करू नका. Chala mitrano — logs, inspect, मग exec.
मित्रों, पहले restart न करें। Chala mitrano — logs, inspect, फिर exec।
Quick answer
Hold this vertical picture:
- ps -a।
- logs।
- inspect।
- exec।
- fix+verify।
Language: English · मराठी · हिंदी
Container debug card
Debug card क्यों
रात को EC2 पर गिरे container को शांत क्रम चाहिए।
Why: State बदलने से पहले error।
What: ps, logs, inspect, exec।
How: Lab पर card।
Example 1: List all containers
Type this:
command -v docker >/dev/null && docker ps -a --format "table {{.Names}}\t{{.Status}}\t{{.Image}}" || printf "%s\n" "NAMES STATUS IMAGE\napi Exited (1) myapi:1"
You will see:
NAMES STATUS IMAGE
api Exited (1) myapi:1
What it means: Exit code 1 means the process failed — start with logs.
Example 2: Read recent logs
Type this:
printf "%s\n" "docker logs --tail 100 api"
You will see:
docker logs --tail 100 api
What it means: Tail keeps noise down; add -f to follow live.
Example 12: Debug card
Type this:
printf "%s\n" "1 ps -a 2 logs 3 inspect 4 exec 5 fix 6 verify"
You will see:
1 ps -a 2 logs 3 inspect 4 exec 5 fix 6 verify
What it means: Say this card in TCS Docker rounds.
Concept 1: पहले logs
जवाब आखिरी lines में।
Why: Stack/missing env।
What: logs --tail/-f/--since
How: फिर exit code।
Example 2: Read recent logs
Type this:
printf "%s\n" "docker logs --tail 100 api"
You will see:
docker logs --tail 100 api
What it means: Tail keeps noise down; add -f to follow live.
Example 3: Follow logs mindset
Type this:
printf "%s\n" "docker logs -f --since 10m api"
You will see:
docker logs -f --since 10m api
What it means: since 10m focuses on the latest incident window.
Example 4: Inspect exit and mounts
Type this:
printf "%s\n" "docker inspect api --format '{{.State.Status}} {{.State.ExitCode}}'"
You will see:
docker inspect api --format '{{.State.Status}} {{.State.ExitCode}}'
What it means: inspect exposes status, exit code, env, and mounts.
Example 11: OOM hint
Type this:
printf "%s\n" "Exit 137 often means OOM kill" "Check memory limits next"
You will see:
Exit 137 often means OOM kill
Check memory limits next
What it means: 137 is a classic interview signal.
Concept 2: inspect/exec
Config और shell।
Why: Env, mounts।
What: inspect; exec
How: Secrets ticket में नहीं।
Example 5: Inspect env keys (no secret values in demos)
Type this:
printf "%s\n" "docker inspect api --format '{{range .Config.Env}}{{println .}}{{end}}' | cut -d= -f1"
You will see:
docker inspect api --format '{{range .Config.Env}}{{println .}}{{end}}' | cut -d= -f1
What it means: Print keys only in shared screens — never paste secret values into chats.
Example 6: Exec a shell
Type this:
printf "%s\n" "docker exec -it api sh"
You will see:
What it means: Works only while the container is running; use ps to find a live one.
Example 7: Exec one command
Type this:
printf "%s\n" "docker exec api ls /app"
You will see:
What it means: Non-interactive exec is great for scripts and CI debug steps.
Concept 3: Ports verify
गलत publish।
Why: Host/container map।
What: docker port; ss
How: Fix फिर recreate।
Example 8: Check published ports
Type this:
printf "%s\n" "docker port api" "ss -lntp | head"
You will see:
docker port api
ss -lntp | head
What it means: Mismatch between publish and listen is a common Flipkart lab bug.
Example 9: Copy files out
Type this:
printf "%s\n" "docker cp api:/app/app.log /tmp/app.log"
You will see:
docker cp api:/app/app.log /tmp/app.log
What it means: Pull logs or configs when exec is enough but you need a host file.
Example 10: Restart is last
Type this:
printf "%s\n" "Fix config or image first" "Then docker restart api or recreate"
You will see:
Fix config or image first
Then docker restart api or recreate
What it means: Blind restart loops the same crash.
Debug card
1 ps -a 2 logs 3 inspect 4 exec 5 fix 6 verify
Suppose: Exit 1
Missing env।
Suppose: 137
OOM — limit बढ़ाएँ।
Ravindra Bagale's Tip
On Amazon ECS and plain Docker EC2 at Infosys, the first three commands are logs, inspect, and exec.
Infosys च्या Amazon ECS/Docker EC2 वर पहिल्या तीन: logs, inspect, exec.
Infosys के Amazon ECS/Docker EC2 पर पहली तीन: logs, inspect, exec।
Check yourself (quiz)
Q1. पहला आदेश?
ps -a फिर logs
Q2. 137?
OOM
Q3. exec कब?
Running होने पर
Q4. Env keys?
inspect
Q5. Restart पहले?
नहीं
Q6. cp?
docker cp
Reading tracking
Mark this guide when you finish. Your browser remembers it on this device.
ps → logs → inspect → exec → fix.
Did you understand? Let us try it once more.
Frequently asked questions
First debug step?
docker ps -a then logs.
Exit 137?
Often out-of-memory kill.
exec when stopped?
No — container must be running.
See env safely?
inspect keys; do not paste secret values.
Restart first?
No — logs and inspect first.