C.W.K.
Stream
Lesson 03 of 07 · published

Docker 가 실제로 뭘 하나 — Namespace, cgroup, OverlayFS

~18 min · foundations, kernel

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

Docker 는 wrapper. 진짜 일은 kernel 이 함

Docker 가 container 를 발명했다고 생각하기 쉬워. 아니야. Linux namespace 는 2002 년부터, cgroup 은 2007 년부터, OverlayFS 는 2014 년부터 있었어. Docker (2013) 는 그것들을 쓸만하게 만든 거 — Git 이 Linus 의 content-addressable storage 를 쓸만하게 만든 거랑 같아.

세 기둥

1. Namespace — 각 process 가 뭘 보냐

각 container 는 자기만의 view 를 받아:

  • PID — 자기 process tree (안에서 PID 1 은 앱)
  • NET — 자기 network stack (인터페이스, 라우팅, 포트)
  • MNT — 자기 filesystem mount
  • UTS — 자기 hostname
  • IPC — 자기 shared memory, semaphore
  • USER — 자기 UID/GID 매핑 (rootless 모드)

2. cgroup — container 가 얼마 쓸 수 있냐

Control Group 은 CPU 셰어, 메모리 한도, block IO 대역폭, cgroup 당 PID 수 를 강제해. 폭주하는 container 가 호스트 다 굶기는 게 아니라 자기 벽에 부딪혀.

3. Union filesystem (OverlayFS) — layered image

Image 는 read-only layer 들의 stack 이야. Container 는 그 위에 얇은 writable layer 를 더해. 같은 base layer? 디스크엔 한 번만 저장되고 여러 container 에 mount. "200MB 이미지" pull 했는데 30MB 만 다운받아지는 게 이거야 — 나머진 이미 있는 거지.

Code

안 vs 밖에서 process tree 보기·bash
# Start a container that just sits there
docker run -d --name demo nginx

# From inside: PID 1 is nginx
docker exec demo ps -ef
# UID    PID  PPID  C STIME TTY    TIME CMD
# root     1     0  0 11:00 ?  00:00:00 nginx: master process
# nginx    7     1  0 11:00 ?  00:00:00 nginx: worker process

# From the host: those same processes show up with different PIDs
ps -ef | grep nginx
# root  4127  4099  0 11:00 ?  nginx: master process
# Same process, different PID — that is the PID namespace at work.
cgroup 한도 작동 보기·bash
# Run a memory-greedy container with a 100MB cap
docker run --rm --memory=100m python:3.12-slim python -c \
  'a = bytearray(200*1024*1024)'

# Output:
# Killed   ← OOM killer triggered by the cgroup, not the host

# The host stays healthy. Other containers keep running.
# Without --memory, that allocation could have OOMed your laptop.

External links

Exercise

같은 image 로 container 2개 띄워. 각각 안에서 docker exec ... ps -ef 돌리고, 호스트에선 ps -ef | grep <process> 해. 양쪽에서 PID 적어. 두 문장으로 — 왜 container 안의 PID 1 이 호스트의 PID 1 이 아닌지 설명해.

Progress

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

댓글 0

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

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