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

Ephemeral 문제 — Container 가 왜 까먹나

~10 min · data, concepts

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

Container 는 쓴 거 안 들고 있어

Docker 가 image 위에 더하는 writable layer 는 throwaway. docker rm 이 그거 지워. docker run 으로 같은 image 에서 새 container 띄우면, 새 container 는 image 의 filesystem 에서 시작 — 이전에 쓴 거 사라짐.

이건 feature

Ephemerality 가 container 를 scale 하기 쉽고, 교체 쉽고, patch 쉽게 만드는 거야. 비용은 — persist 해야 하는 건 container writable layer 밖에 살아야 해. 그게 volume 하는 일.

Code

30초 안에 손실 재현·bash
docker run -d --name pg1 -e POSTGRES_PASSWORD=secret postgres:16

# Create a database
docker exec -it pg1 psql -U postgres -c "CREATE DATABASE app;"
docker exec -it pg1 psql -U postgres -d app -c "CREATE TABLE t(x int); INSERT INTO t VALUES(42);"

# Throw it away
docker rm -f pg1

# Fresh container, same image, same name
docker run -d --name pg1 -e POSTGRES_PASSWORD=secret postgres:16
docker exec -it pg1 psql -U postgres -d app -c "SELECT * FROM t;"
# ERROR: database "app" does not exist
# Data was in the writable layer. Layer was deleted. Data is gone.

External links

Exercise

본인이 고른 container 로 위 데이터 손실 재현 (Postgres, Redis, MySQL). 그 다음 데이터 디렉토리에 named volume mount 해서 다시 돌려, 데이터가 docker rm -f + 재생성 거치고 살아남는 거 확인. 두 run 캡처.

Progress

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

댓글 0

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

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