codingstuff.io
ExploreTutorialsProblemsCS Subjects
Get Started
ExploreTutorialsProblemsCS Subjects
Get Started
codingstuff.io

Master the art of building software through interactive tutorials, real-world problems, and guided projects.

Pune, Maharashtra, India

codingstuffmail@gmail.com

Product

  • Explore
  • Tutorials
  • Problems
  • CS Subjects

Company

  • About
  • Contact
  • Privacy Policy
  • Terms & Conditions
  • Sitemap

© 2026 codingstuff.io. All rights reserved.

Built with ❤️ for developers everywhere

/
/
All Tutorials
🐳

Docker

11 / 60 topics
10Docker Networking Basics11Volumes and Bind Mounts30Docker Networking Advanced46Docker Networking Advanced Topics
Tutorials/Docker/Volumes and Bind Mounts
🐳Docker

Volumes and Bind Mounts

Updated 2026-05-15
10 min read

Volumes and Bind Mounts

Introduction

In the world of containerization, managing data persistence is a crucial aspect. Data persistence refers to ensuring that data created or modified by your applications is not lost when containers are stopped or removed. Docker provides two primary mechanisms for achieving this: volumes and bind mounts.

Volumes are managed by Docker and store data in a location on the host filesystem that is completely controlled by Docker. They offer a higher level of abstraction and better performance than bind mounts, especially for larger datasets.

Bind mounts allow you to mount a directory or file from the host directly into the container. This can be useful for development environments where you want to see changes immediately without rebuilding the image.

In this tutorial, we will explore both volumes and bind mounts in detail, understand their differences, and learn how to use them effectively with Docker.

Concept

Volumes

Docker volumes are designed to persist data independently of the container's lifecycle. They are stored in a directory managed by Docker on the host machine. You can create named volumes or anonymous volumes.

Named Volumes

Named volumes have a user-defined name and can be reused across multiple containers. They provide better management and easier debugging.

Anonymous Volumes

Anonymous volumes do not have a user-defined name and are removed when the container is deleted unless they are explicitly specified to persist.

Bind Mounts

Bind mounts allow you to mount any directory or file from the host machine into the container. This can be particularly useful for development, where you want to see changes in real-time without rebuilding the image.

Examples

Using Volumes

Let's start by creating a named volume and using it with a Docker container.

Step 1: Create a Named Volume

First, we create a named volume called myvolume.

Terminal

This command runs an Nginx container and mounts myvolume at /app inside the container.

Step 3: Verify the Volume

We can verify that the volume is mounted by inspecting the container.

Terminal

Step 2: Run a Container with the Bind Mount

Run a container and bind mount the directory we just created.

Terminal

Now, start an interactive shell in the running container and check if the file exists.

Terminal
Output
Hello, Docker!

Differences Between Volumes and Bind Mounts

  • Management: Volumes are managed by Docker and stored in a location controlled by Docker. Bind mounts directly use the host filesystem.
  • Portability: Volumes are more portable across different hosts because they are managed by Docker. Bind mounts depend on the specific path on the host, making them less portable.
  • Performance: Volumes generally offer better performance for larger datasets due to optimizations in how Docker manages them.

What's Next?

Now that you have a good understanding of volumes and bind mounts, you can explore more advanced topics such as Docker Swarm Basics. Docker Swarm allows you to manage multiple Docker hosts as a single virtual host, providing high availability and scalability for your applications.

Feel free to experiment with different configurations and scenarios to deepen your understanding of data persistence in Docker. Happy coding!


PreviousDocker Networking BasicsNext Docker Swarm Basics

Recommended Gear

Docker Networking BasicsDocker Swarm Basics