C.W.K.
Stream
Lesson 05 of 05 · published

실행 중인 Container 안 보기 — exec, logs, inspect

~16 min · commands, debugging

Level 0Container 호기심
0 XP0/36 lessons0/10 achievements
0/120 XP to next level120 XP to go0% complete

디버깅 트리오

실행 중인 container 에 뭔가 잘못됐을 때, 명령 셋이 질문의 90% 에 답해.

docker logs — 첫 정거장

메인 process 가 stdout/stderr 에 쓰는 건 다 잡혀. 무조건 logs 부터 봐 — 대부분 거기 보여.

docker exec — 안에 들어가

docker exec 는 이미 실행 중인 container 안에서 새 process 돌려. docker run 이랑 달라 — run 은 새 container 만듦. 쑤시고 다닐 땐 exec: ls, ps, cat /etc/..., 또는 interactive shell.

docker inspect — 메타데이터 호스

container 에 대해 Docker 가 아는 모든 걸 거대한 JSON 으로 줘: state, network, mount, env var, restart count, exit code. --format 으로 Go template 써서 특정 필드 뽑아.

Code

트리아지 시퀀스·bash
# Step 1: Is it running?
docker ps -a | grep myapp

# Step 2: What did it say?
docker logs --tail 100 myapp
docker logs -f myapp           # follow in real time
docker logs --since 10m myapp  # last 10 minutes

# Step 3: Get inside
docker exec -it myapp /bin/sh   # alpine
docker exec -it myapp /bin/bash # debian/ubuntu base

# Step 4: Pull specific facts out
docker inspect --format '{{.State.Status}}' myapp
docker inspect --format '{{.State.ExitCode}}' myapp
docker inspect --format '{{.NetworkSettings.IPAddress}}' myapp
exec 으로 일회성 명령·bash
# Run a Django migration in an existing container
docker exec -it api python manage.py migrate

# Check Postgres health from the DB container itself
docker exec db pg_isready -U postgres

# Tail a log file inside the container
docker exec -it api tail -f /app/logs/app.log

External links

Exercise

5초 후 죽는 container 띄워 (예: docker run --name flaky alpine sh -c 'echo hi; sleep 5; exit 1'). 죽고 나서 docker logsdocker inspect 로 출력이랑 exit code 회수해. 두 명령 적어.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.