Ravindra BagaleCourses & study guides मराठी Track your progress

Guides

Running Docker Container Debug कसे करावे (logs, exec, inspect)

ps, logs, inspect, exec — नंतर restart. कारण fix, recreate, verify.

Friends, never restart first. Chala mitrano — logs, inspect, then exec.

Quick answer

Hold this vertical picture:

  1. ps -a.
  2. logs.
  3. inspect.
  4. exec.
  5. fix+verify.

Language: English · मराठी · हिंदी

docker ps -aSee exit code docker logsRead the error docker inspectEnv mounts image docker execShell inside Fix and recreateVerify health
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:

docker exec -it api sh

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:

docker exec api ls /app

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.

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.

Copy files?

docker cp

Restart first?

No — logs and inspect first.