Back to course

Lesson 13: Bind Mounts vs. Volumes (Development vs. Production)

Docker Zero to Hero: The Complete Containerization Course for Beginners

Lesson 13: Bind Mounts vs. Volumes (Development vs. Production)

While volumes are ideal for persistent data (like databases), Bind Mounts offer more control and are typically preferred for development and testing environments.

Bind Mounts Explained

A bind mount mounts a specific host file or directory path directly into the container. The host path must exist.

Usage: Real-time code synchronization (Hot Reloading).

Example: Development Hot Reloading

Assume your Node.js application code is in /home/user/my-node-app on your host.

bash docker run -d \n --name node_dev \n -p 3000:3000 \n -v /home/user/my-node-app:/app \n node:20-alpine npm run dev

Explanation of -v for Bind Mounts:

  • -v /home/user/my-node-app: The absolute path on the host.
  • :: Separator.
  • /app: The path inside the container (where the WORKDIR is usually set).

Now, if you edit a file on your host machine (e.g., server.js), the change is instantly reflected inside the container, speeding up development.

Comparison Table

FeatureDocker VolumesBind Mounts
Primary UsePersistent Database Data, shared storageDevelopment (Code Sync), configuration
Host ManagementManaged by Docker (Location is hard to find)User manages (Must specify absolute path)
CreationCreated by Docker or CLICreated automatically if path exists
SafetySafer, avoids accidental changes to host filesCan overwrite or modify host files
PortabilityHighly PortableLess portable (requires specific host path)

Rule of Thumb:

  • Production: Use Volumes.
  • Development/Debugging: Use Bind Mounts.