Simplify Data Persistence in Docker with Volumes and Bind Mounts

π Hello! I'm passionate about DevOps and have over 1+ years of experience in the field. I'm proficient in a variety of cutting-edge technologies and always motivated to expand my knowledge and skills. Let's connect and grow together!
SKILLS:
πΉ Languages & Runtimes: Python, Shell Scripting, HCL, YAML πΉ Cloud Technologies: AWS, Microsoft Azure, GCP πΉ Infrastructure Tools: Docker, Terraform, AWS CloudFormation πΉ Other Tools: Linux, Git and GitHub Actions, Jenkins, Jira, GitLab (beginner), Docker, AWS DevOps πΉ Web Development: HTML, CSS, Bootstrap, Python, SQL
Job & Responsibilities:
π Improved development efficiency by implementing CI/CD pipelines, resulting in a 30% reduction in deployment time on the test server. π Strengthened deployment and testing reliability by utilizing Docker containers and optimizing Dockerfile, reducing development issues on the test server by 20%. βοΈ Automated S3 bucket log creation with Shell scripting, eliminating 100% of manual search and saving 2 hours per week. π Scheduled EC2 instance start/stop using Lambda functions and Event Bridge, leading to a 25% decrease in infrastructure costs. π§ Utilized AWS, Linux, Python, Docker, Shell scripting, Terraform, Jenkins Pipelines, and automation to streamline workflows and improve overall system performance.
I'm very detail-oriented and possess strong written and verbal communication skills. As a high performer with a possibility mindset, I strive to solve problems using efficient approaches.
Let's Connect & Grow:
If you find my profile suitable for the role you are searching for, please feel free to reach out to me at sumanprasad9766@gmail.com.
π Introduction:
If you've ever used Docker, you might have encountered a common problem - the data you store in a Docker container disappears when the container dies. This is because the file system of a Docker container is deleted when the container is removed.
Fortunately, Docker provides two solutions to this problem - volumes and bind mounts. In this blog post, we'll take a closer look at both of these solutions and see how you can use them to persist data beyond the lifetime of containers.
As Docker containers are ephemeral, it is essential to persist data beyond the lifetime of the container. Docker volumes and bind directories on a host as a mount are the two ways of handling data persistence in Docker containers. In this guide, we'll explore these two approaches and their key differences.
π What are Docker Volumes? π€

Docker volumes provide a way to store data on the host file system that persists even if the container is deleted and recreated. This approach provides better flexibility than bind mounts and can be backed up separately from the host file system. Volumes can also be moved between containers and hosts.
π How to Create and Manage Docker Volumes? π οΈ
You can create and manage Docker volumes using the docker volume command. Let's see how we can create a new volume and mount it to a container:
πΉ Create Volume:
# Creating a new volume
docker volume create <volume_name>
Any data written to the /data directory inside the container will be persisted in the volume on the host file system.
πΉ List docker volumes:
docker volume ls
πΉ Mounting a Volume
Once you've created a volume, you can mount it to a container using the -v or --mount option when running a docker run command. For example:
docker run -it -v <volume_name>:/data <image_name> /bin/bash
This command will mount the volume <volume_name> to the /data directory in the container. Any data written to the /data directory inside the container will be persisted in the volume on the host file system.
π What are Bind Directories on a Host as a Mount? π€
Bind mounts allow you to mount a directory from the host file system into a container. This approach has the same behaviour as volumes but is specified using a host path instead of a volume name.
πΉ For example:
docker run -it -v <host_path>:<container_path> <image_name> /bin/bash
πΉ Key Differences between Docker Volumes and Bind Directories on a Host as a Mount π
Volumes are better suited for more complex use cases where you need more control over the data being persisted in the container. In contrast, bind directories on a host as a mount are appropriate for simple use cases where you need to mount a directory from the host file system into a container.
π Conclusion:
In summary, Docker volumes and bind directories on a host as a mount provide different ways to handle data persistence in Docker containers. Choose the approach that best fits your use case to ensure that your data is persisted beyond the lifetime of the container. π
Hashtags:
#Docker #Volumes #BindMounts #DataPersistence #Containers #DevOps




