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

Lifecycle — ps, stop, start, kill, rm, prune

~14 min · commands, lifecycle

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

Container 상태 머신

created → running → paused → stopped → removed

각 전환에 명령이 있어. Container 가 말 안 들을 때 옳은 거 알아두는 게 중요해.

  • docker ps실행 중 container 나열. -a 로 stopped 포함.
  • docker stop <name> — SIGTERM 보내고 10초 기다리고 SIGKILL. graceful.
  • docker kill <name> — 즉시 SIGKILL. stop 이 안 멈출 때만.
  • docker start <name> — stopped container 재시작.
  • docker restart <name> — stop 후 start.
  • docker rm <name> — stopped container 제거. -f 로 실행 중인 거 강제 제거.

정리 명령

  • docker container prune — 모든 stopped container 제거.
  • docker image prune — dangling (untagged) image 제거.
  • docker system prune -a --volumes — 안 쓰는 image, container, network, 그리고 volume 까지 핵폭. flag 두 번 읽어.

Code

일상 정리 워크플로·bash
# What's running?
docker ps

# What has run?
docker ps -a --format 'table {{.Names}}\t{{.Status}}\t{{.Image}}'

# Stop everything
docker stop $(docker ps -q)

# Remove stopped containers
docker container prune -f

# Remove dangling images (safe)
docker image prune -f

# Check disk usage before going nuclear
docker system df
핵 옵션 (두 번 읽기)·bash
# Removes:
#  - all stopped containers
#  - all unused networks
#  - all unused images (not just dangling)
#  - ALL volumes that aren't used by any container
#
# That last one will delete database data if no container is
# currently mounting it. There is no undo.
docker system prune -a --volumes

External links

Exercise

Container 띄우고 안에 파일 써, stop (제거 X). docker start 로 다시 살려. 파일 그대로? 그 다음 docker rm -f 하고 같은 image 로 새 container docker run. 파일 있어? 두 문장으로 차이 설명.

Progress

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

댓글 0

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

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