Storage (Volumes)

コンテナは「使い捨て」です。データを永続化するには「Volume」が必要です。

1. Volumes vs Bind Mounts

📦 Volumes

Dockerが管理する領域。

Best for: Database data (MySQL/Postgres), Logs.

📂 Bind Mounts

ホストのパスを直接マウント。

Best for: Config files (`nginx.conf`), Source code (during Dev).

2. Implementation (Compose)

docker-compose.yml
version: '3.8'
services:
db:
image: postgres:15
volumes:
# Named Volume (Managed by Docker)
- db-data:/var/lib/postgresql/data
web:
image: nginx
volumes:
# Bind Mount (Linked to host file)
- ./nginx.conf:/etc/nginx/nginx.conf:ro
volumes:
db-data: