Volumes vs. Bind Mounts

Difficulty: Intermediate

Question

Compare Docker Volumes and Bind Mounts.

Answer

- **Volumes**: Managed by Docker in a specific part of the host filesystem (`/var/lib/docker/volumes`). Recommended for production because they are isolated from host OS specifics. - **Bind Mounts**: A directory or file on the host machine is mounted into a container. They depend on the host's directory structure and are great for local development (e.g., hot-reloading code).

Code examples

Mounting syntax

# Volume (recommended)
docker run -v my-vol:/app nginx

# Bind Mount (dev only)
docker run -v $(pwd):/app nginx

Volumes are abstract and managed; Bind Mounts are direct links to host files.

Key points

Concepts covered

Persistence, Storage, Mounting