{"id":2046,"date":"2019-11-04T02:50:55","date_gmt":"2019-11-04T02:50:55","guid":{"rendered":"http:\/\/kusuaks7\/?p=1651"},"modified":"2024-03-05T15:43:54","modified_gmt":"2024-03-05T15:43:54","slug":"pump-up-the-volumes-data-in-docker","status":"publish","type":"post","link":"https:\/\/www.experfy.com\/blog\/bigdata-cloud\/pump-up-the-volumes-data-in-docker\/","title":{"rendered":"Pump up the Volumes: Data in Docker"},"content":{"rendered":"\t\t<div data-elementor-type=\"wp-post\" data-elementor-id=\"2046\" class=\"elementor elementor-2046\" data-elementor-post-type=\"post\">\n\t\t\t\t\t\t<section class=\"has_eae_slider elementor-section elementor-top-section elementor-element elementor-element-1ce3b7f1 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"1ce3b7f1\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"has_eae_slider elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-1f7bd9a3\" data-id=\"1f7bd9a3\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-f5d6c50 elementor-widget elementor-widget-heading\" data-id=\"f5d6c50\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h3 class=\"elementor-heading-title elementor-size-default\"><h3 style=\"color: #aaa;font-style: italic\"><strong>Part 6 of Learn Enough Docker to be Useful<\/strong><\/h3><\/h3>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-0487e02 elementor-widget elementor-widget-text-editor\" data-id=\"0487e02\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\tThis article is about using data with Docker. In it, we\u2019ll focus on Docker volumes. Check out the previous articles in the series if you haven\u2019t yet. We covered Docker <a href=\"https:\/\/www.experfy.com\/blog\/learn-enough-docker-to-be-useful-part1-the-conceptual-landscape\">concepts<\/a>, the Docker <a href=\"https:\/\/www.experfy.com\/blog\/learn-enough-docker-to-be-useful-part-2-a-delicious-dozen-docker-terms-you-need-to-know\">ecosystems<\/a>, <a href=\"https:\/\/www.experfy.com\/blog\/learn-enough-docker-to-be-useful-part-3-a-dozen-dandy-dockerfile-instructions\">Dockerfiles<\/a>, <a href=\"https:\/\/www.experfy.com\/blog\/slimming-down-your-docker-images-part-4-of-learn-enough-docker-to-be-useful\">slimming down images<\/a>, <a href=\"https:\/\/www.experfy.com\/blog\/learn-enough-docker-to-be-useful-part-3-a-dozen-dandy-dockerfile-instructions\">popular commands<\/a>.\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-db9ea45 elementor-widget elementor-widget-text-editor\" data-id=\"db9ea45\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p id=\"af48\" data-selectable-paragraph=\"\">Pushing the food metaphor running through these articles to the breaking point, let\u2019s compare data in Docker to spices. Just as there are many spices in the world, there are many ways to save data with Docker.<\/p>\n\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-ab5266e elementor-widget elementor-widget-image\" data-id=\"ab5266e\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<img decoding=\"async\" src=\"https:\/\/miro.medium.com\/max\/200\/1*EJx9QN4ENSPKZuz51rC39w.png\" alt=\"\" \/>\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-1ec9bcf elementor-widget elementor-widget-text-editor\" data-id=\"1ec9bcf\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p id=\"e875\" data-selectable-paragraph=\"\">Quick FYI: this guide is current for Docker Engine Version 18.09.1 and API\u00a0<a href=\"https:\/\/docs.docker.com\/engine\/api\/version-history\/\" target=\"_blank\" rel=\"noopener noreferrer\" class=\"broken_link\">version 1.39<\/a>.<\/p>\n<p id=\"cb3f\" data-selectable-paragraph=\"\">Data in Docker can either be temporary or persistent. Let\u2019s check out temporary data first.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-64ea742 elementor-widget elementor-widget-heading\" data-id=\"64ea742\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h1 class=\"elementor-heading-title elementor-size-default\"><h1 id=\"9e7f\" data-selectable-paragraph=\"\">Temporary Data<\/h1>\n<\/h1>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-7c2737a elementor-widget elementor-widget-text-editor\" data-id=\"7c2737a\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p id=\"2bfd\" data-selectable-paragraph=\"\">Data can be kept temporarily inside a Docker container in two ways.<\/p>\n<p id=\"4d1e\" data-selectable-paragraph=\"\">By default, files created by an application inside a container are stored in the writable layer of the container. You don\u2019t have to set anything up. This is the quick and dirty way. Just save a file and go about your business. However, when you container ceases to exist, so will your data.<\/p>\n<p id=\"4f16\" data-selectable-paragraph=\"\">You have another option if you want better performance for saving temporary data with Docker. If you don\u2019t need your data to persist beyond the life of the container, a\u00a0<em>tmpfs<\/em>\u00a0mount is a temporary mount that uses the host\u2019s memory. A tmpfs mount has the benefit of faster read and write operations.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-ec6ec69 elementor-widget elementor-widget-text-editor\" data-id=\"ec6ec69\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p id=\"ecae\" data-selectable-paragraph=\"\">Many times you will want your data to exist even after the container is long gone. You need to persist your data.<\/p>\n\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-eeee1a3 elementor-widget elementor-widget-heading\" data-id=\"eeee1a3\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\"><h1 id=\"26de\" data-selectable-paragraph=\"\">Persistent Data<\/h1>\n<\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-613cd0c elementor-widget elementor-widget-text-editor\" data-id=\"613cd0c\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p id=\"3618\" data-selectable-paragraph=\"\">There are two ways to persist data beyond the life of the container. One way is to\u00a0<em>bind mount<\/em>\u00a0a file system to the container. With a bind mount, processes outside Docker also can modify the data.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-503c19b elementor-widget elementor-widget-image\" data-id=\"503c19b\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<img decoding=\"async\" src=\"https:\/\/miro.medium.com\/max\/502\/1*9X1xxsG5K9kXAmg_5EM9bg.png\" alt=\"\" \/>\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-c060f81 elementor-widget elementor-widget-text-editor\" data-id=\"c060f81\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p style=\"text-align: center;\" data-selectable-paragraph=\"\"><span style=\"font-size: 11px;\">From the\u00a0<a href=\"https:\/\/docs.docker.com\/storage\/volumes\/\" target=\"_blank\" rel=\"noopener noreferrer\">Docker Docs<\/a><\/span><\/p>\n<p id=\"febe\" data-selectable-paragraph=\"\">Bind mounts are difficult to back up, migrate, or share with other Containers. Volumes are a better way to persist data.<\/p>\n\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-2b313ea elementor-widget elementor-widget-heading\" data-id=\"2b313ea\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h1 class=\"elementor-heading-title elementor-size-default\"><h1 id=\"1d8c\" data-selectable-paragraph=\"\">Volumes<\/h1><\/h1>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-22fc620 elementor-widget elementor-widget-text-editor\" data-id=\"22fc620\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p id=\"6e95\" data-selectable-paragraph=\"\">A Volume is a a file system that lives on a host machine outside of any container. Volumes are created and managed by Docker. Volumes are:<\/p>\n\n<ul>\n \t<li id=\"1c07\" data-selectable-paragraph=\"\">persistent<\/li>\n \t<li id=\"134a\" data-selectable-paragraph=\"\">free-floating filesystems, separate from any one container<\/li>\n \t<li id=\"bca8\" data-selectable-paragraph=\"\">sharable with other containers<\/li>\n \t<li id=\"d52e\" data-selectable-paragraph=\"\">efficient for input and output<\/li>\n \t<li id=\"e8d6\" data-selectable-paragraph=\"\">able to be hosted on remote cloud providers<\/li>\n \t<li id=\"70f1\" data-selectable-paragraph=\"\">encryptable<\/li>\n \t<li id=\"6e33\" data-selectable-paragraph=\"\">nameable<\/li>\n \t<li id=\"c208\" data-selectable-paragraph=\"\">able to have their content pre-populated by a container<\/li>\n \t<li id=\"3b7c\" data-selectable-paragraph=\"\">handy for testing<\/li>\n<\/ul>\n<p id=\"530f\" data-selectable-paragraph=\"\">That\u2019s a lot of useful functionality! Now let\u2019s look at how you make a Volume.<\/p>\n\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-8a3a392 elementor-widget elementor-widget-image\" data-id=\"8a3a392\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<img decoding=\"async\" src=\"https:\/\/miro.medium.com\/max\/640\/1*dt0MgRXGQAueVUyGXFyUjA.jpeg\" alt=\"\" \/>\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-4712020 elementor-widget elementor-widget-text-editor\" data-id=\"4712020\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p style=\"text-align: center;\" data-selectable-paragraph=\"\"><span style=\"font-size: 11px;\">Volumes<\/span><\/p>\n\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-be5378a elementor-widget elementor-widget-heading\" data-id=\"be5378a\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\"><h2 id=\"1fc4\" data-selectable-paragraph=\"\">Creating Volumes<\/h2><\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-269dfbb elementor-widget elementor-widget-text-editor\" data-id=\"269dfbb\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p id=\"5be4\" data-selectable-paragraph=\"\">Volumes can be created via a Dockerfile or an API request.<\/p>\n<p id=\"76b2\" data-selectable-paragraph=\"\">Here\u2019s a Dockerfile instruction that creates a volume at run time:<\/p>\n<p id=\"803f\" data-selectable-paragraph=\"\"><code>VOLUME \/my_volume<\/code><\/p>\n<p id=\"6baf\" data-selectable-paragraph=\"\">Then, when the container is created, Docker will create the volume with any data that already exists at the specified location.\u00a0<mark>Note that if you create a volume using a Dockerfile, you still need to declare the mountpoint for the volume at run time.<\/mark><\/p>\n<p id=\"896e\" data-selectable-paragraph=\"\">You can also create a volume in a Dockerfile using JSON array formatting. See\u00a0<a href=\"https:\/\/towardsdatascience.com\/learn-enough-docker-to-be-useful-b0b44222eef5\" target=\"_blank\" rel=\"noopener noreferrer\">this earlier article<\/a>\u00a0in this series for more on Dockerfiles.<\/p>\n<p id=\"f1fe\" data-selectable-paragraph=\"\">Volumes also can be instantiated at run time from the command line.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-053de13 elementor-widget elementor-widget-heading\" data-id=\"053de13\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h1 class=\"elementor-heading-title elementor-size-default\"><h1 id=\"3c16\" data-selectable-paragraph=\"\">Volume CLI Commands<\/h1><\/h1>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-d75831e elementor-widget elementor-widget-heading\" data-id=\"d75831e\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\"><h2 id=\"6448\" data-selectable-paragraph=\"\">Create<\/h2><\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-fddb1e5 elementor-widget elementor-widget-text-editor\" data-id=\"fddb1e5\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p id=\"483a\" data-selectable-paragraph=\"\">You can create a stand-alone volume with\u00a0<code>docker volume create \u2014-name my_volume<\/code>.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-3cd6f62 elementor-widget elementor-widget-heading\" data-id=\"3cd6f62\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\"><h2 id=\"1a06\" data-selectable-paragraph=\"\">Inspect<\/h2><\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-2d6003d elementor-widget elementor-widget-text-editor\" data-id=\"2d6003d\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p id=\"642a\" data-selectable-paragraph=\"\">List Docker volumes with\u00a0<code>docker volume ls<\/code>.<\/p>\n<p id=\"c7b5\" data-selectable-paragraph=\"\">Volumes can be inspected with\u00a0<code>docker volume inspect my_volume<\/code>.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-d7cb738 elementor-widget elementor-widget-heading\" data-id=\"d7cb738\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\">\n<h2 id=\"30e8\" data-selectable-paragraph=\"\">Remove<\/h2><\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-1638fa8 elementor-widget elementor-widget-text-editor\" data-id=\"1638fa8\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p id=\"dc97\" data-selectable-paragraph=\"\">Then you can delete the volume with\u00a0<code>docker volume rm my_volume<\/code>.<\/p>\n<p id=\"cecf\" data-selectable-paragraph=\"\">Dangling volumes are volumes not used by a container. You can remove all dangling volumes with\u00a0<code>docker volume prune<\/code>. Docker will warn you and ask for confirmation before deletion.<\/p>\n<p id=\"4877\" data-selectable-paragraph=\"\">If the volume is associated with any containers, you cannot remove it until the containers are deleted. Even then, Docker sometimes doesn\u2019t realize that the containers are gone. If this occurs, you can use\u00a0<code><a href=\"http:\/\/docker-compose%20down%20--volumes\/\" target=\"_blank\" rel=\"noopener noreferrer\">docker system prune<\/a><\/code>\u00a0to clean up all your Docker resources. Then you should should be able to delete the volume.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-57c2820 elementor-widget elementor-widget-image\" data-id=\"57c2820\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<img decoding=\"async\" src=\"https:\/\/miro.medium.com\/max\/640\/1*-ORM_SLKftoJjOSnhgHLVw.jpeg\" alt=\"\" \/>\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-202a733 elementor-widget elementor-widget-text-editor\" data-id=\"202a733\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p style=\"text-align: center;\" data-selectable-paragraph=\"\"><span style=\"font-size: 11px;\">Where your data might be stored<\/span><\/p>\n<p id=\"b4e4\" data-selectable-paragraph=\"\"><strong>Working with\u00a0<\/strong><code><strong>--mount<\/strong><\/code><strong>\u00a0vs.\u00a0<\/strong><code><strong>--volume<\/strong><\/code><\/p>\n<p id=\"7256\" data-selectable-paragraph=\"\">You will often use flags to refer to your volumes. For example, to create a volume at the same time you create a container use the following:<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-0184535 elementor-widget elementor-widget-text-editor\" data-id=\"0184535\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p id=\"197d\" data-selectable-paragraph=\"\"><code>docker container run --mount source=my_volume, target=\/container\/path\/for\/volume my_image<\/code><\/p>\n<p id=\"b33f\" data-selectable-paragraph=\"\">In the old days (i.e. pre-2017) the\u00a0<code>--volume<\/code>\u00a0flag was popular. Originally, the\u00a0<code>-v<\/code>\u00a0or\u00a0<code>--volume<\/code>\u00a0flag was used for standalone containers and the\u00a0<code>--mount<\/code>\u00a0flag was used with Docker Swarms. However, beginning with Docker 17.06, you can use\u00a0<code>--mount<\/code>\u00a0in all cases.<\/p>\n<p id=\"9fc0\" data-selectable-paragraph=\"\">The syntax for\u00a0<code>--mount<\/code>\u00a0is a bit more verbose, but it\u2019s preferred over\u00a0<code>--volume<\/code>\u00a0for several reasons.\u00a0<code>--mount<\/code>\u00a0is the only way you can work with services or specify volume driver options. It\u2019s also simpler to use.<\/p>\n<p id=\"af33\" data-selectable-paragraph=\"\">You\u2019ll see a lot of\u00a0<code>-v<\/code>\u2019s in existing code. Beware that the format for the options is different for\u00a0<code>--mount<\/code>\u00a0and\u00a0<code>--volume<\/code>. You often can\u2019t just replace a\u00a0<code>-v<\/code>\u00a0in your existing code with a\u00a0<code>--mount<\/code>\u00a0and be done with it.<\/p>\n<p id=\"112f\" data-selectable-paragraph=\"\">The biggest difference is that the\u00a0<code>-v<\/code>\u00a0syntax combines all the options together in one field, while the\u00a0<code>--mount<\/code>\u00a0syntax separates them. Let\u2019s see\u00a0<code>--mount<\/code>\u00a0in action!<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-26c9c4e elementor-widget elementor-widget-image\" data-id=\"26c9c4e\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<img decoding=\"async\" src=\"https:\/\/miro.medium.com\/max\/1280\/1*B3qV4FtVSBmhp9vS-m7ReA.jpeg\" alt=\"\" \/>\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-72e8543 elementor-widget elementor-widget-text-editor\" data-id=\"72e8543\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p style=\"text-align: center;\" data-selectable-paragraph=\"\"><span style=\"font-size: 11px;\">Easy enough to mount<\/span><\/p>\n<p id=\"e526\" data-selectable-paragraph=\"\"><code><strong>--mount<\/strong><\/code><strong>\u00a0<\/strong>\u2014 options are key-value pairs. Each pair is formatted like this:\u00a0<code>key=value<\/code>, with a comma between one pair and the next. Common options:<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"has_eae_slider elementor-section elementor-top-section elementor-element elementor-element-70cb602 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"70cb602\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"has_eae_slider elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-c113416\" data-id=\"c113416\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-e201f97 elementor-widget elementor-widget-text-editor\" data-id=\"e201f97\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\ttype\u00a0\u2014 mount type. Options are\u00a0bind,\u00a0volume, or\u00a0tmpfs. We\u2019re all about the\u00a0volume.\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-1f138b6 elementor-widget elementor-widget-text-editor\" data-id=\"1f138b6\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\tsource\u00a0\u2014 source of the mount. For named volumes, this is the name of the volume. For unnamed volumes, this option is omitted. The key can be shortened to\u00a0src.\ndestination\u00a0\u2014 the path where the file or directory is mounted in the container. The key can be shortened to\u00a0dst\u00a0or\u00a0target.\nreadonly\u00a0\u2014mounts the volume as\u00a0read-only. Optional. Takes no value.\n\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-7994170 elementor-widget elementor-widget-text-editor\" data-id=\"7994170\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\tHere\u2019s an example with lots of options:\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-0a4274d elementor-widget elementor-widget-text-editor\" data-id=\"0a4274d\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\ndocker run &#8211;mount type=volume,source=volume_name,destination=\/path\/in\/container,readonly my_image\n\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-38315a9 elementor-widget elementor-widget-image\" data-id=\"38315a9\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<img fetchpriority=\"high\" decoding=\"async\" width=\"1024\" height=\"680\" src=\"https:\/\/www.experfy.com\/blog\/wp-content\/uploads\/2019\/11\/1_oegIeUqU2Lcs2I1KYlUjSQ-1024x680.jpeg\" class=\"attachment-large size-large wp-image-36239\" alt=\"\" srcset=\"https:\/\/www.experfy.com\/blog\/wp-content\/uploads\/2019\/11\/1_oegIeUqU2Lcs2I1KYlUjSQ-1024x680.jpeg 1024w, https:\/\/www.experfy.com\/blog\/wp-content\/uploads\/2019\/11\/1_oegIeUqU2Lcs2I1KYlUjSQ-300x199.jpeg 300w, https:\/\/www.experfy.com\/blog\/wp-content\/uploads\/2019\/11\/1_oegIeUqU2Lcs2I1KYlUjSQ-768x510.jpeg 768w, https:\/\/www.experfy.com\/blog\/wp-content\/uploads\/2019\/11\/1_oegIeUqU2Lcs2I1KYlUjSQ-1536x1020.jpeg 1536w, https:\/\/www.experfy.com\/blog\/wp-content\/uploads\/2019\/11\/1_oegIeUqU2Lcs2I1KYlUjSQ-610x405.jpeg 610w, https:\/\/www.experfy.com\/blog\/wp-content\/uploads\/2019\/11\/1_oegIeUqU2Lcs2I1KYlUjSQ-750x498.jpeg 750w, https:\/\/www.experfy.com\/blog\/wp-content\/uploads\/2019\/11\/1_oegIeUqU2Lcs2I1KYlUjSQ-1140x757.jpeg 1140w, https:\/\/www.experfy.com\/blog\/wp-content\/uploads\/2019\/11\/1_oegIeUqU2Lcs2I1KYlUjSQ.jpeg 1920w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/>\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-82ad879 elementor-widget elementor-widget-text-editor\" data-id=\"82ad879\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\tVolumes are like spices \u2014 they make most things better.\u00a0\n\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-f69ffc7 elementor-widget elementor-widget-heading\" data-id=\"f69ffc7\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\">Wrap<\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"has_eae_slider elementor-section elementor-top-section elementor-element elementor-element-c4d5dc6 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"c4d5dc6\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"has_eae_slider elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-40e8db0\" data-id=\"40e8db0\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-d7a06fb elementor-widget elementor-widget-heading\" data-id=\"d7a06fb\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h3 class=\"elementor-heading-title elementor-size-default\">Recap of Key Volume Commands<\/h3>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-0efab2b elementor-widget elementor-widget-text-editor\" data-id=\"0efab2b\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<ul><li id=\"4ee1\" data-selectable-paragraph=\"\"><code>docker volume create<\/code><\/li><li id=\"563c\" data-selectable-paragraph=\"\"><code>docker volume ls<\/code><\/li><li id=\"5f4c\" data-selectable-paragraph=\"\"><code>docker volume inspect<\/code><\/li><li id=\"c2cf\" data-selectable-paragraph=\"\"><code>docker volume rm<\/code><\/li><li id=\"d782\" data-selectable-paragraph=\"\"><code>docker volume prune<\/code><\/li><\/ul>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-d1c79e1 elementor-widget elementor-widget-text-editor\" data-id=\"d1c79e1\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\tCommon options for the\u00a0&#8211;mount\u00a0flag in\u00a0docker run &#8211;mount my_options my_image:\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-a3743ef elementor-widget elementor-widget-text-editor\" data-id=\"a3743ef\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<ul><li id=\"d085\" data-selectable-paragraph=\"\"><code>type=volume<\/code><\/li><li id=\"e184\" data-selectable-paragraph=\"\"><code>source=volume_name<\/code><\/li><li id=\"e56a\" data-selectable-paragraph=\"\"><code>destination=\/path\/in\/container<\/code><\/li><li id=\"09a6\" data-selectable-paragraph=\"\"><code>readonly<\/code><\/li><\/ul>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<\/div>\n\t\t","protected":false},"excerpt":{"rendered":"<p>This article familiarizes you with data storage in Docker. &nbsp;There are many ways to save data with Docker. Data in Docker can either be temporary or persistent.&nbsp;Data can be kept temporarily inside a Docker container in two ways. Many times you will want your data to exist even after the container is long gone. Many times you will want your data to exist even after the container is long gone. You need to persist your data.<\/p>\n","protected":false},"author":369,"featured_media":2621,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"content-type":"","footnotes":""},"categories":[187],"tags":[94],"ppma_author":[2134],"class_list":["post-2046","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-bigdata-cloud","tag-data-science"],"authors":[{"term_id":2134,"user_id":369,"is_guest":0,"slug":"jeff-hale","display_name":"Jeff Hale","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/?s=96&d=mm&r=g","user_url":"","last_name":"Hale","first_name":"Jeff","job_title":"","description":"Jeff Hale is a co-founder of Rebel Desk, where he oversees technology, finance, and operations for this company. He&nbsp;is an experienced entrepreneur who has managed technology, operations, and finances for several companies.&nbsp;"}],"_links":{"self":[{"href":"https:\/\/www.experfy.com\/blog\/wp-json\/wp\/v2\/posts\/2046","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.experfy.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.experfy.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.experfy.com\/blog\/wp-json\/wp\/v2\/users\/369"}],"replies":[{"embeddable":true,"href":"https:\/\/www.experfy.com\/blog\/wp-json\/wp\/v2\/comments?post=2046"}],"version-history":[{"count":6,"href":"https:\/\/www.experfy.com\/blog\/wp-json\/wp\/v2\/posts\/2046\/revisions"}],"predecessor-version":[{"id":36242,"href":"https:\/\/www.experfy.com\/blog\/wp-json\/wp\/v2\/posts\/2046\/revisions\/36242"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.experfy.com\/blog\/wp-json\/wp\/v2\/media\/2621"}],"wp:attachment":[{"href":"https:\/\/www.experfy.com\/blog\/wp-json\/wp\/v2\/media?parent=2046"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.experfy.com\/blog\/wp-json\/wp\/v2\/categories?post=2046"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.experfy.com\/blog\/wp-json\/wp\/v2\/tags?post=2046"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.experfy.com\/blog\/wp-json\/wp\/v2\/ppma_author?post=2046"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}