{"id":5129,"date":"2024-11-08T10:52:14","date_gmt":"2024-11-08T10:52:14","guid":{"rendered":"https:\/\/www.liainfraservices.com\/blog\/?p=5129"},"modified":"2025-02-25T07:28:19","modified_gmt":"2025-02-25T07:28:19","slug":"how-to-create-persistent-data-storage-in-docker-volumes-and-bind-mounts","status":"publish","type":"post","link":"https:\/\/www.liainfraservices.com\/blog\/how-to-create-persistent-data-storage-in-docker-volumes-and-bind-mounts\/","title":{"rendered":"Persistent Data Storage in Docker: Docker Volumes and Bind Mounts"},"content":{"rendered":"<span class=\"span-reading-time rt-reading-time\" style=\"display: block;\"><span class=\"rt-label rt-prefix\"><\/span> <span class=\"rt-time\"> 4<\/span> <span class=\"rt-label rt-postfix\">min read<\/span><\/span><div class='epvc-post-count'><span class='epvc-eye'><\/span>  <span class=\"epvc-count\"> 4,282<\/span><\/div>\n<p class=\"wp-block-paragraph\">Accidently you executed <strong>docker rm -f mysql<\/strong> and that broke your entire application, but you are smart, you created the container again, but still the application is not able to bring old data.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You have seen some weird words in internet like &#8211;mount and then mydata:\/some\/path and you dont know what these means and how thats even related. Worry not, lets understand that and learn how to solve the problem of data lost and about the syntaxes that we see often on google or some document.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Lets see that together &#8211; <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Docker containers are often ephemeral, meaning they\u2019re designed to run processes and discard data upon exit(same as the first problem that we discussed above). <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">But what if you need certain data to persist beyond the lifecycle of a container? This is where <strong>persistent storage<\/strong> comes into play, allowing data to live on your host system(ex : laptop), even if containers are stopped, restarted, or deleted.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In this blog, we&#8217;ll cover three main aspects:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>What are Docker Volumes and Bind Mounts?<\/strong><\/li>\n\n\n\n<li><strong>How to Set Up Persistent Storage in Docker<\/strong><\/li>\n\n\n\n<li><strong>Benefits and Limitations of Different Docker Storage Options<\/strong><\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">Let\u2019s dive into each phase to get a solid grasp on making data in Docker containers persist!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">1. What Are Docker Volumes and Bind Mounts?<\/h2>\n\n\n\n<ol class=\"wp-block-list\"><\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">Docker offers two primary ways to manage persistent data:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Volumes<\/strong>: Managed by Docker, volumes are stored in a specific Docker directory on the host, but Docker manages their lifecycle and storage location.\n<ul class=\"wp-block-list\">\n<li>Remember, if we dont give that volume a name, docker creates a random number and that becomes difficult to manage or attach with other containers.<\/li>\n\n\n\n<li>We human does not have any control, only docker can manage its lifecycle<\/li>\n\n\n\n<li>To know its location, we can do inspect of the container and look for mounts block (docker inspect mysql-container)<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Bind Mounts<\/strong>: Allows you to specify an exact path on your host machine to bind to a path within the container. With bind mounts, you control where the data lives.\n<ul class=\"wp-block-list\">\n<li>Generally developers uses this and map their development workspace with some directory inside the container<\/li>\n\n\n\n<li>The classic example is mapping the working space with nginx root path (source=$(pwd),target=\/usr\/share\/nginx\/)<\/li>\n\n\n\n<li>Or, mapping the log directory of container <\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Why Use Persistent Storage?<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Persistent storage is crucial when dealing with databases, configuration files, application logs, or any data you want to access or maintain across container restarts. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For instance, without persistent storage, all the database data would disappear when a container is removed, making data recovery a challenge.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>2. Setting Up Persistent Storage in Docker<\/strong><\/h2>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Using Volumes in Docker<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">We can create volumes in Docker in three ways: inline while creating a container, with <code>docker volume create<\/code>, or through <code>docker-compose<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Lets see all these 3 methods of creating volume in details below<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Method 1: Creating a Named Volume Inline with <code>--mount<\/code><\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">To create a named volume directly when running a container, use the <code>--mount<\/code> option:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker run -d --name mysql-container --mount source=my_db_data,target=\/var\/lib\/mysql mysql:latest<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Here:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>source=my_db_data<\/code> tells Docker to create a named volume called <code>my_db_data<\/code>.<\/li>\n\n\n\n<li><code>target=\/var\/lib\/mysql<\/code> this specifies the path inside the container where the volume will be mounted.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">This approach is useful when you want Docker to manage the storage, ensuring data in <code>\/var\/lib\/mysql<\/code> persists even if the container is removed.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Method 2: Using <code>docker volume create<\/code><\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">To have more control over volume creation, you can create a volume first and then mount it to a container:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker volume create my_app_data\ndocker run -d --name app-container --mount source=my_app_data,target=\/app\/data myapp:latest<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Method 3: Using Docker Compose for Volumes<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Docker Compose simplifies multi-container setups by defining configurations in a YAML file. Here\u2019s how you can set up a volume in <code>docker-compose.yml<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>version: '3.8'\nservices:\n  db:\n    image: mysql:latest\n    volumes:\n      - db_data:\/var\/lib\/mysql\n\nvolumes:\n  db_data:<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">In this example, <code>db_data<\/code> is a named volume that persists database files on the host.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Lets see, how many of you got this as a question or curiosity, as how to know which path inside the container needs to be mapped with some named volume in local laptop\/host machine.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">here, the colon (:) seperates the path between local &amp; container and it can be read like this <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">local_laptop_path:inside_container_path<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you are curious, how to decide how to identify this path <strong>\/var\/lib\/mysql<\/strong> inside the container   db_data:\/var\/lib\/mysql<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Then to find the answer of this, we have to go to the public repo and see the image and the key informations are already present there.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Inspecting Docker Volumes<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">To verify the volume and its mount details, use:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker inspect mysql-container<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">In the output, look for the <code>Mounts<\/code> section to see details such as the <code>Source<\/code> (host path) and <code>Destination<\/code> (container path).<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\"Mounts\": &#91;\n            {\n                \"Type\": \"volume\",\n                \"Name\": \"docker_dbdata\",\n                \"Source\": \"\/var\/lib\/docker\/volumes\/docker_dbdata\/_data\",\n                \"Destination\": \"\/var\/lib\/mysql\",\n                \"Driver\": \"local\",\n                \"Mode\": \"z\",\n                \"RW\": true,\n                \"Propagation\": \"\"\n            }\n        ],\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>3. Using Bind Mounts for More Control<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Bind mounts offer a different approach by giving you full control over where the data lives on the host. You specify the exact path on your host machine that should be accessible from within the container.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Creating a Container with a Bind Mount<\/strong><\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>docker run -d --name web-container --mount type=bind,source=$(pwd)\/my-website,target=\/usr\/share\/nginx\/html -p 80:80 nginx<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">In this example:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>type=bind<\/code> indicates that we\u2019re using a bind mount.<\/li>\n\n\n\n<li><code>source=$(pwd)\/my-website<\/code> points to the <code>my-website<\/code> directory on the host machine.<\/li>\n\n\n\n<li><code>target=\/usr\/share\/nginx\/html<\/code> is the directory inside the container where <code>my-website<\/code> will be accessible.<\/li>\n<\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">Just a side note:<\/p>\n<\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\">We can pass more than two bind mounts through command, but, here we will see its difficult and it may produce errors, so the discovery of docker compose made it better. <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker run -d \\\n  --name website \\\n  -p 80:80 \\\n  --mount type=bind,source=$(pwd)\/website_files,target=\/usr\/share\/nginx\/html \\\n  --mount type=bind,source=$(pwd)\/nginx_logs\/error.log,target=\/var\/log\/nginx\/error.log \\\n  website\n\nTo know more about docker compose, please read it from here https:\/\/www.liainfraservices.com\/blog\/how-to-set-up-a-local-development-environment-using-docker-compose\/<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If you inspect this container with <code>docker inspect web-container<\/code>, the <code>Mounts<\/code> section will reveal the host directory bound to the container\u2019s filesystem:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&#8220;Mounts&#8221;: [<br>{<br>&#8220;Type&#8221;: &#8220;bind&#8221;,<br>&#8220;Source&#8221;: &#8220;\/Users\/macbook\/my-website&#8221;,<br>&#8220;Destination&#8221;: &#8220;\/usr\/share\/nginx\/html&#8221;,<br>&#8220;RW&#8221;: true<br>}<br>]<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Advantages of Bind Mounts<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Full control<\/strong>: You decide exactly where on the host the data lives.<\/li>\n\n\n\n<li><strong>Real-time updates<\/strong>: Any changes made on the host directory are immediately reflected in the container, and vice versa.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>4. Benefits and Limitations of Docker Volumes vs. Bind Mounts<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Both storage methods have their own pros and cons:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-background has-fixed-layout\" style=\"background:linear-gradient(90deg,rgb(255,245,203) 0%,rgb(182,227,212) 50%,rgb(51,167,181) 100%)\"><thead><tr><th>Feature<\/th><th>Volumes<\/th><th>Bind Mounts<\/th><\/tr><\/thead><tbody><tr><td><strong>Managed by<\/strong><\/td><td>Docker<\/td><td>Host (defined path)<\/td><\/tr><tr><td><strong>Flexibility<\/strong><\/td><td>Docker decides storage location<\/td><td>User specifies exact path<\/td><\/tr><tr><td><strong>Security<\/strong><\/td><td>More secure, Docker manages permissions<\/td><td>Less secure, full access to host path<\/td><\/tr><tr><td><strong>Sharing Data<\/strong><\/td><td>Easily shared among containers<\/td><td>Possible but with extra caution<\/td><\/tr><tr><td><strong>Suitability<\/strong><\/td><td>Suitable for app data, databases, logs<\/td><td>Great for development, real-time updates<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Example Scenarios<\/strong>:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Use <strong>named volumes<\/strong> for production databases, app data, or logs that need persistence but minimal intervention.<\/li>\n\n\n\n<li>Use <strong>bind mounts<\/strong> in development to reflect host changes in real-time within containers, which is ideal for working with code or config files.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Persistent data is a core aspect of any application relying on Docker containers, whether in development or production. Understanding when to use volumes versus bind mounts helps you make smart storage decisions that suit your application\u2019s needs.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">By following this guide, you now know:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>How to create volumes and bind mounts in Docker.<\/li>\n\n\n\n<li>How to configure persistent data with Docker Compose.<\/li>\n\n\n\n<li>The benefits and limitations of each storage type.<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">If you enjoyed so far, then I am sure you will enjoy this also where I dived deep into docker compose: <a href=\"https:\/\/www.liainfraservices.com\/blog\/how-to-set-up-a-local-development-environment-using-docker-compose\/\">https:\/\/www.liainfraservices.com\/blog\/how-to-set-up-a-local-development-environment-using-docker-compose\/<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><br><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p><span class=\"span-reading-time rt-reading-time\" style=\"display: block;\"><span class=\"rt-label rt-prefix\"><\/span> <span class=\"rt-time\"> 4<\/span> <span class=\"rt-label rt-postfix\">min read<\/span><\/span>4,282 Accidently you executed docker rm -f mysql and that broke your entire application, but you are smart, you created the container again, but still the application is not able<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":true,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"footnotes":""},"categories":[971],"tags":[],"class_list":["post-5129","post","type-post","status-publish","format-standard","hentry","category-devops"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Persistent Data Storage in Docker: Docker Volumes and Bind Mounts - Blog | Liainfraservices<\/title>\n<meta name=\"description\" content=\"Afraid of using docker as a tool during application development, because it may lose all the data if the container is terminated? docker volume and bind mount can provide a great solution to this. Lets see which solution to use between docker volume vs bind mounts.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.liainfraservices.com\/blog\/how-to-create-persistent-data-storage-in-docker-volumes-and-bind-mounts\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Persistent Data Storage in Docker: Docker Volumes and Bind Mounts - Blog | Liainfraservices\" \/>\n<meta property=\"og:description\" content=\"Afraid of using docker as a tool during application development, because it may lose all the data if the container is terminated? docker volume and bind mount can provide a great solution to this. Lets see which solution to use between docker volume vs bind mounts.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.liainfraservices.com\/blog\/how-to-create-persistent-data-storage-in-docker-volumes-and-bind-mounts\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog | Liainfraservices\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-08T10:52:14+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-02-25T07:28:19+00:00\" \/>\n<meta name=\"author\" content=\"Partho\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Partho\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.liainfraservices.com\\\/blog\\\/how-to-create-persistent-data-storage-in-docker-volumes-and-bind-mounts\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.liainfraservices.com\\\/blog\\\/how-to-create-persistent-data-storage-in-docker-volumes-and-bind-mounts\\\/\"},\"author\":{\"name\":\"Partho\",\"@id\":\"https:\\\/\\\/www.liainfraservices.com\\\/blog\\\/#\\\/schema\\\/person\\\/b5a729cb152dd3bc7f07550ca9d223e4\"},\"headline\":\"Persistent Data Storage in Docker: Docker Volumes and Bind Mounts\",\"datePublished\":\"2024-11-08T10:52:14+00:00\",\"dateModified\":\"2025-02-25T07:28:19+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.liainfraservices.com\\\/blog\\\/how-to-create-persistent-data-storage-in-docker-volumes-and-bind-mounts\\\/\"},\"wordCount\":1129,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.liainfraservices.com\\\/blog\\\/#organization\"},\"articleSection\":[\"devops\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.liainfraservices.com\\\/blog\\\/how-to-create-persistent-data-storage-in-docker-volumes-and-bind-mounts\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.liainfraservices.com\\\/blog\\\/how-to-create-persistent-data-storage-in-docker-volumes-and-bind-mounts\\\/\",\"url\":\"https:\\\/\\\/www.liainfraservices.com\\\/blog\\\/how-to-create-persistent-data-storage-in-docker-volumes-and-bind-mounts\\\/\",\"name\":\"Persistent Data Storage in Docker: Docker Volumes and Bind Mounts - Blog | Liainfraservices\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.liainfraservices.com\\\/blog\\\/#website\"},\"datePublished\":\"2024-11-08T10:52:14+00:00\",\"dateModified\":\"2025-02-25T07:28:19+00:00\",\"description\":\"Afraid of using docker as a tool during application development, because it may lose all the data if the container is terminated? docker volume and bind mount can provide a great solution to this. Lets see which solution to use between docker volume vs bind mounts.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.liainfraservices.com\\\/blog\\\/how-to-create-persistent-data-storage-in-docker-volumes-and-bind-mounts\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.liainfraservices.com\\\/blog\\\/how-to-create-persistent-data-storage-in-docker-volumes-and-bind-mounts\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.liainfraservices.com\\\/blog\\\/how-to-create-persistent-data-storage-in-docker-volumes-and-bind-mounts\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.liainfraservices.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"devops\",\"item\":\"https:\\\/\\\/www.liainfraservices.com\\\/blog\\\/category\\\/devops\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Persistent Data Storage in Docker: Docker Volumes and Bind Mounts\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.liainfraservices.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.liainfraservices.com\\\/blog\\\/\",\"name\":\"Blog | Liainfraservices\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.liainfraservices.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.liainfraservices.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.liainfraservices.com\\\/blog\\\/#organization\",\"name\":\"Blog | Liainfraservices\",\"url\":\"https:\\\/\\\/www.liainfraservices.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.liainfraservices.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.liainfraservices.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/10\\\/lia-logo-b-e1635340384244.png\",\"contentUrl\":\"https:\\\/\\\/www.liainfraservices.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/10\\\/lia-logo-b-e1635340384244.png\",\"width\":308,\"height\":96,\"caption\":\"Blog | Liainfraservices\"},\"image\":{\"@id\":\"https:\\\/\\\/www.liainfraservices.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.liainfraservices.com\\\/blog\\\/#\\\/schema\\\/person\\\/b5a729cb152dd3bc7f07550ca9d223e4\",\"name\":\"Partho\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/6c5fc8918cc5dbc844eccbeaaf854eef27d2c79ab17ff0022304f712805d6959?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/6c5fc8918cc5dbc844eccbeaaf854eef27d2c79ab17ff0022304f712805d6959?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/6c5fc8918cc5dbc844eccbeaaf854eef27d2c79ab17ff0022304f712805d6959?s=96&d=mm&r=g\",\"caption\":\"Partho\"},\"description\":\"Partho Das, founder of Lia Infraservices, has 15+ years of expertise in cloud solutions, DevOps, and infrastructure security. He provides consultation on architecture planning, DevOps setup, Kubernetes, and cloud migrations. Partho holds multiple AWS and Azure certifications, along with CISCO CCNA &amp; CCNP. Connect on LinkedIn\",\"sameAs\":[\"https:\\\/\\\/www.linkedin.com\\\/in\\\/partho-dev\\\/\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Persistent Data Storage in Docker: Docker Volumes and Bind Mounts - Blog | Liainfraservices","description":"Afraid of using docker as a tool during application development, because it may lose all the data if the container is terminated? docker volume and bind mount can provide a great solution to this. Lets see which solution to use between docker volume vs bind mounts.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.liainfraservices.com\/blog\/how-to-create-persistent-data-storage-in-docker-volumes-and-bind-mounts\/","og_locale":"en_US","og_type":"article","og_title":"Persistent Data Storage in Docker: Docker Volumes and Bind Mounts - Blog | Liainfraservices","og_description":"Afraid of using docker as a tool during application development, because it may lose all the data if the container is terminated? docker volume and bind mount can provide a great solution to this. Lets see which solution to use between docker volume vs bind mounts.","og_url":"https:\/\/www.liainfraservices.com\/blog\/how-to-create-persistent-data-storage-in-docker-volumes-and-bind-mounts\/","og_site_name":"Blog | Liainfraservices","article_published_time":"2024-11-08T10:52:14+00:00","article_modified_time":"2025-02-25T07:28:19+00:00","author":"Partho","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Partho","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.liainfraservices.com\/blog\/how-to-create-persistent-data-storage-in-docker-volumes-and-bind-mounts\/#article","isPartOf":{"@id":"https:\/\/www.liainfraservices.com\/blog\/how-to-create-persistent-data-storage-in-docker-volumes-and-bind-mounts\/"},"author":{"name":"Partho","@id":"https:\/\/www.liainfraservices.com\/blog\/#\/schema\/person\/b5a729cb152dd3bc7f07550ca9d223e4"},"headline":"Persistent Data Storage in Docker: Docker Volumes and Bind Mounts","datePublished":"2024-11-08T10:52:14+00:00","dateModified":"2025-02-25T07:28:19+00:00","mainEntityOfPage":{"@id":"https:\/\/www.liainfraservices.com\/blog\/how-to-create-persistent-data-storage-in-docker-volumes-and-bind-mounts\/"},"wordCount":1129,"commentCount":0,"publisher":{"@id":"https:\/\/www.liainfraservices.com\/blog\/#organization"},"articleSection":["devops"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.liainfraservices.com\/blog\/how-to-create-persistent-data-storage-in-docker-volumes-and-bind-mounts\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.liainfraservices.com\/blog\/how-to-create-persistent-data-storage-in-docker-volumes-and-bind-mounts\/","url":"https:\/\/www.liainfraservices.com\/blog\/how-to-create-persistent-data-storage-in-docker-volumes-and-bind-mounts\/","name":"Persistent Data Storage in Docker: Docker Volumes and Bind Mounts - Blog | Liainfraservices","isPartOf":{"@id":"https:\/\/www.liainfraservices.com\/blog\/#website"},"datePublished":"2024-11-08T10:52:14+00:00","dateModified":"2025-02-25T07:28:19+00:00","description":"Afraid of using docker as a tool during application development, because it may lose all the data if the container is terminated? docker volume and bind mount can provide a great solution to this. Lets see which solution to use between docker volume vs bind mounts.","breadcrumb":{"@id":"https:\/\/www.liainfraservices.com\/blog\/how-to-create-persistent-data-storage-in-docker-volumes-and-bind-mounts\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.liainfraservices.com\/blog\/how-to-create-persistent-data-storage-in-docker-volumes-and-bind-mounts\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.liainfraservices.com\/blog\/how-to-create-persistent-data-storage-in-docker-volumes-and-bind-mounts\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.liainfraservices.com\/blog\/"},{"@type":"ListItem","position":2,"name":"devops","item":"https:\/\/www.liainfraservices.com\/blog\/category\/devops\/"},{"@type":"ListItem","position":3,"name":"Persistent Data Storage in Docker: Docker Volumes and Bind Mounts"}]},{"@type":"WebSite","@id":"https:\/\/www.liainfraservices.com\/blog\/#website","url":"https:\/\/www.liainfraservices.com\/blog\/","name":"Blog | Liainfraservices","description":"","publisher":{"@id":"https:\/\/www.liainfraservices.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.liainfraservices.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.liainfraservices.com\/blog\/#organization","name":"Blog | Liainfraservices","url":"https:\/\/www.liainfraservices.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.liainfraservices.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.liainfraservices.com\/blog\/wp-content\/uploads\/2021\/10\/lia-logo-b-e1635340384244.png","contentUrl":"https:\/\/www.liainfraservices.com\/blog\/wp-content\/uploads\/2021\/10\/lia-logo-b-e1635340384244.png","width":308,"height":96,"caption":"Blog | Liainfraservices"},"image":{"@id":"https:\/\/www.liainfraservices.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/www.liainfraservices.com\/blog\/#\/schema\/person\/b5a729cb152dd3bc7f07550ca9d223e4","name":"Partho","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/6c5fc8918cc5dbc844eccbeaaf854eef27d2c79ab17ff0022304f712805d6959?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/6c5fc8918cc5dbc844eccbeaaf854eef27d2c79ab17ff0022304f712805d6959?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/6c5fc8918cc5dbc844eccbeaaf854eef27d2c79ab17ff0022304f712805d6959?s=96&d=mm&r=g","caption":"Partho"},"description":"Partho Das, founder of Lia Infraservices, has 15+ years of expertise in cloud solutions, DevOps, and infrastructure security. He provides consultation on architecture planning, DevOps setup, Kubernetes, and cloud migrations. Partho holds multiple AWS and Azure certifications, along with CISCO CCNA &amp; CCNP. Connect on LinkedIn","sameAs":["https:\/\/www.linkedin.com\/in\/partho-dev\/"]}]}},"_links":{"self":[{"href":"https:\/\/www.liainfraservices.com\/blog\/wp-json\/wp\/v2\/posts\/5129","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.liainfraservices.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.liainfraservices.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.liainfraservices.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.liainfraservices.com\/blog\/wp-json\/wp\/v2\/comments?post=5129"}],"version-history":[{"count":7,"href":"https:\/\/www.liainfraservices.com\/blog\/wp-json\/wp\/v2\/posts\/5129\/revisions"}],"predecessor-version":[{"id":5136,"href":"https:\/\/www.liainfraservices.com\/blog\/wp-json\/wp\/v2\/posts\/5129\/revisions\/5136"}],"wp:attachment":[{"href":"https:\/\/www.liainfraservices.com\/blog\/wp-json\/wp\/v2\/media?parent=5129"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.liainfraservices.com\/blog\/wp-json\/wp\/v2\/categories?post=5129"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.liainfraservices.com\/blog\/wp-json\/wp\/v2\/tags?post=5129"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}