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

Named Volume — State 의 옳은 디폴트

~14 min · data, volumes

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

Named volume 은 Docker 관리 스토리지

이름 줘. Docker 가 /var/lib/docker/volumes/<name>/_data 밑에 저장. Container 랑 무관하게 살아 — docker rm 살아남고, image rebuild 살아남고, 명시적으로 지울 때만 사라져.

Code

Volume CRUD·bash
# Create explicitly (optional — auto-created on first use)
docker volume create pgdata

# List
docker volume ls

# Inspect (where it lives, options, labels)
docker volume inspect pgdata

# Remove (only when no container uses it)
docker volume rm pgdata

# Remove all unused volumes (ASK YOURSELF FIRST)
docker volume prune
Postgres 가 container 삭제 살아남기·bash
# First container
docker run -d --name db \
  -v pgdata:/var/lib/postgresql/data \
  -e POSTGRES_PASSWORD=secret \
  postgres:16

# Insert data
docker exec -it db psql -U postgres -c "CREATE TABLE t(x int); INSERT INTO t VALUES(7);"

# Tear down completely
docker rm -f db

# Recreate
docker run -d --name db \
  -v pgdata:/var/lib/postgresql/data \
  -e POSTGRES_PASSWORD=secret \
  postgres:16

# Verify
docker exec -it db psql -U postgres -c "SELECT * FROM t;"
# x | 7  ← still there

External links

Exercise

전형적 웹 stack 용 named volume 셋: app-pgdata, app-redisdata, app-uploads. Postgres, Redis, /app/uploads/test.txt 파일 쓰는 stub web container 돌려. 셋 다 docker rm -f 로 내리고, 같은 volume 으로 재생성, 다 무사한지 확인.

Progress

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

댓글 0

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

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