{"id":4823,"date":"2018-01-12T06:46:08","date_gmt":"2018-01-12T06:46:08","guid":{"rendered":"http:\/\/www.scmgalaxy.com\/tutorials\/?p=4823"},"modified":"2021-02-27T10:12:53","modified_gmt":"2021-02-27T10:12:53","slug":"docker-compose-prepends-current-directory-name-to-named-volumes","status":"publish","type":"post","link":"https:\/\/www.scmgalaxy.com\/tutorials\/docker-compose-prepends-current-directory-name-to-named-volumes\/","title":{"rendered":"docker-compose prepends current directory name to named volumes"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-4848 aligncenter\" src=\"https:\/\/www.scmgalaxy.com\/tutorials\/wp-content\/uploads\/2018\/01\/docker-compose.png\" alt=\"docker-compose\" width=\"600\" height=\"400\" srcset=\"https:\/\/www.scmgalaxy.com\/tutorials\/wp-content\/uploads\/2018\/01\/docker-compose.png 600w, https:\/\/www.scmgalaxy.com\/tutorials\/wp-content\/uploads\/2018\/01\/docker-compose-300x200.png 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/p>\n<p>Issues &#8211;\u00a0docker-compose prepends current directory name to named volumes<\/p>\n<p>What actually happens is that the named volume gets prepended with (a simplified version of) the directory name from which the docker-compose command was run.<\/p>\n<p>For instance, if I run from the &#8220;dcompos-programs&#8221; directory, and I name the volume &#8220;my_named_vol&#8221;, then I end up with a volume named &#8220;dcompos-programs_my_named_vol&#8221;.<\/p>\n<p><strong>docker-compose-named-volume.yml:<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n\r\nversion: '3'\r\nservices:\r\n\r\nsolr:\r\n image: alpine:3.5\r\n container_name: foo\r\n volumes:\r\n - my_named_vol:\/opt\/foo\r\nvolumes:\r\n my_named_vol:\r\n\r\n<\/pre>\n<p><strong>Result:<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n\r\n$ docker-compose -f docker-compose-named-volume.yml up -d &amp;amp;&amp;amp; \\\r\n&amp;gt; echo &quot;## named volume:&quot; &amp;amp;&amp;amp; \\\r\n&amp;gt; docker volume ls | grep my_named_vol &amp;amp;&amp;amp; \\\r\n&amp;gt; echo &quot;## stop&quot; &amp;amp;&amp;amp; \\\r\n&amp;gt; docker-compose -f docker-compose-named-volume.yml down &amp;amp;&amp;amp; \\\r\n&amp;gt; echo &quot;## rm volume&quot; &amp;amp;&amp;amp; \\\r\n&amp;gt; docker volume rm $(docker volume ls | grep my_named_vol | awk '{print $2}')\r\nCreating network &quot;deploymentroot_default&quot; with the default driver\r\nCreating volume &quot;dcompos-programs_my_named_vol&quot; with default driver\r\nCreating foo\r\n\r\n<\/pre>\n<p><strong>Answer<\/strong><br \/>\ndocker-compose uses a project name. By default it\u2019s the directory name which prevents collisions with existing containers. But you can use -p to change the prefix name.<\/p>\n<p>You can use the external volume setting to avoid the prefix.<br \/>\n<a href=\"https:\/\/docs.docker.com\/compose\/compose-file\/#external\">https:\/\/docs.docker.com\/compose\/compose-file\/#external<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Issues &#8211;\u00a0docker-compose prepends current directory name to named volumes What actually happens is that the named volume gets prepended with [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":4848,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[4862],"tags":[567,4863],"class_list":["post-4823","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-docker","tag-docker","tag-docker-compose"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>docker-compose prepends current directory name to named volumes - scmGalaxy<\/title>\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.scmgalaxy.com\/tutorials\/docker-compose-prepends-current-directory-name-to-named-volumes\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"docker-compose prepends current directory name to named volumes - scmGalaxy\" \/>\n<meta property=\"og:description\" content=\"Issues &#8211;\u00a0docker-compose prepends current directory name to named volumes What actually happens is that the named volume gets prepended with [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.scmgalaxy.com\/tutorials\/docker-compose-prepends-current-directory-name-to-named-volumes\/\" \/>\n<meta property=\"og:site_name\" content=\"scmGalaxy\" \/>\n<meta property=\"article:published_time\" content=\"2018-01-12T06:46:08+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-02-27T10:12:53+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.scmgalaxy.com\/tutorials\/wp-content\/uploads\/2018\/01\/docker-compose.png\" \/>\n\t<meta property=\"og:image:width\" content=\"600\" \/>\n\t<meta property=\"og:image:height\" content=\"400\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"scmgalaxy K\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"scmgalaxy K\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/docker-compose-prepends-current-directory-name-to-named-volumes\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/docker-compose-prepends-current-directory-name-to-named-volumes\\\/\"},\"author\":{\"name\":\"scmgalaxy K\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/#\\\/schema\\\/person\\\/fc12ad190f540e79460243c81148d102\"},\"headline\":\"docker-compose prepends current directory name to named volumes\",\"datePublished\":\"2018-01-12T06:46:08+00:00\",\"dateModified\":\"2021-02-27T10:12:53+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/docker-compose-prepends-current-directory-name-to-named-volumes\\\/\"},\"wordCount\":248,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/docker-compose-prepends-current-directory-name-to-named-volumes\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/wp-content\\\/uploads\\\/2018\\\/01\\\/docker-compose.png\",\"keywords\":[\"Docker\",\"docker-compose\"],\"articleSection\":[\"Docker\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/docker-compose-prepends-current-directory-name-to-named-volumes\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/docker-compose-prepends-current-directory-name-to-named-volumes\\\/\",\"url\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/docker-compose-prepends-current-directory-name-to-named-volumes\\\/\",\"name\":\"docker-compose prepends current directory name to named volumes - scmGalaxy\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/docker-compose-prepends-current-directory-name-to-named-volumes\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/docker-compose-prepends-current-directory-name-to-named-volumes\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/wp-content\\\/uploads\\\/2018\\\/01\\\/docker-compose.png\",\"datePublished\":\"2018-01-12T06:46:08+00:00\",\"dateModified\":\"2021-02-27T10:12:53+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/#\\\/schema\\\/person\\\/fc12ad190f540e79460243c81148d102\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/docker-compose-prepends-current-directory-name-to-named-volumes\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/docker-compose-prepends-current-directory-name-to-named-volumes\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/docker-compose-prepends-current-directory-name-to-named-volumes\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/wp-content\\\/uploads\\\/2018\\\/01\\\/docker-compose.png\",\"contentUrl\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/wp-content\\\/uploads\\\/2018\\\/01\\\/docker-compose.png\",\"width\":600,\"height\":400,\"caption\":\"docker-compose\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/docker-compose-prepends-current-directory-name-to-named-volumes\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"docker-compose prepends current directory name to named volumes\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/#website\",\"url\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/\",\"name\":\"scmGalaxy\",\"description\":\"A Platform for Software Engineers\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/#\\\/schema\\\/person\\\/fc12ad190f540e79460243c81148d102\",\"name\":\"scmgalaxy K\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4b902ea8c77ee0a326c112f29d0edf51b7c3e1cd05c4fb92a810177e9c3f12a9?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4b902ea8c77ee0a326c112f29d0edf51b7c3e1cd05c4fb92a810177e9c3f12a9?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4b902ea8c77ee0a326c112f29d0edf51b7c3e1cd05c4fb92a810177e9c3f12a9?s=96&d=mm&r=g\",\"caption\":\"scmgalaxy K\"},\"sameAs\":[\"http:\\\/\\\/www.DevOpsSchool.com\"],\"url\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/author\\\/scmgalaxy\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"docker-compose prepends current directory name to named volumes - scmGalaxy","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.scmgalaxy.com\/tutorials\/docker-compose-prepends-current-directory-name-to-named-volumes\/","og_locale":"en_US","og_type":"article","og_title":"docker-compose prepends current directory name to named volumes - scmGalaxy","og_description":"Issues &#8211;\u00a0docker-compose prepends current directory name to named volumes What actually happens is that the named volume gets prepended with [&hellip;]","og_url":"https:\/\/www.scmgalaxy.com\/tutorials\/docker-compose-prepends-current-directory-name-to-named-volumes\/","og_site_name":"scmGalaxy","article_published_time":"2018-01-12T06:46:08+00:00","article_modified_time":"2021-02-27T10:12:53+00:00","og_image":[{"width":600,"height":400,"url":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-content\/uploads\/2018\/01\/docker-compose.png","type":"image\/png"}],"author":"scmgalaxy K","twitter_card":"summary_large_image","twitter_misc":{"Written by":"scmgalaxy K","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/docker-compose-prepends-current-directory-name-to-named-volumes\/#article","isPartOf":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/docker-compose-prepends-current-directory-name-to-named-volumes\/"},"author":{"name":"scmgalaxy K","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/#\/schema\/person\/fc12ad190f540e79460243c81148d102"},"headline":"docker-compose prepends current directory name to named volumes","datePublished":"2018-01-12T06:46:08+00:00","dateModified":"2021-02-27T10:12:53+00:00","mainEntityOfPage":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/docker-compose-prepends-current-directory-name-to-named-volumes\/"},"wordCount":248,"commentCount":0,"image":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/docker-compose-prepends-current-directory-name-to-named-volumes\/#primaryimage"},"thumbnailUrl":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-content\/uploads\/2018\/01\/docker-compose.png","keywords":["Docker","docker-compose"],"articleSection":["Docker"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.scmgalaxy.com\/tutorials\/docker-compose-prepends-current-directory-name-to-named-volumes\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/docker-compose-prepends-current-directory-name-to-named-volumes\/","url":"https:\/\/www.scmgalaxy.com\/tutorials\/docker-compose-prepends-current-directory-name-to-named-volumes\/","name":"docker-compose prepends current directory name to named volumes - scmGalaxy","isPartOf":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/docker-compose-prepends-current-directory-name-to-named-volumes\/#primaryimage"},"image":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/docker-compose-prepends-current-directory-name-to-named-volumes\/#primaryimage"},"thumbnailUrl":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-content\/uploads\/2018\/01\/docker-compose.png","datePublished":"2018-01-12T06:46:08+00:00","dateModified":"2021-02-27T10:12:53+00:00","author":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/#\/schema\/person\/fc12ad190f540e79460243c81148d102"},"breadcrumb":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/docker-compose-prepends-current-directory-name-to-named-volumes\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.scmgalaxy.com\/tutorials\/docker-compose-prepends-current-directory-name-to-named-volumes\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/docker-compose-prepends-current-directory-name-to-named-volumes\/#primaryimage","url":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-content\/uploads\/2018\/01\/docker-compose.png","contentUrl":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-content\/uploads\/2018\/01\/docker-compose.png","width":600,"height":400,"caption":"docker-compose"},{"@type":"BreadcrumbList","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/docker-compose-prepends-current-directory-name-to-named-volumes\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.scmgalaxy.com\/tutorials\/"},{"@type":"ListItem","position":2,"name":"docker-compose prepends current directory name to named volumes"}]},{"@type":"WebSite","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/#website","url":"https:\/\/www.scmgalaxy.com\/tutorials\/","name":"scmGalaxy","description":"A Platform for Software Engineers","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.scmgalaxy.com\/tutorials\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/#\/schema\/person\/fc12ad190f540e79460243c81148d102","name":"scmgalaxy K","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4b902ea8c77ee0a326c112f29d0edf51b7c3e1cd05c4fb92a810177e9c3f12a9?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4b902ea8c77ee0a326c112f29d0edf51b7c3e1cd05c4fb92a810177e9c3f12a9?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4b902ea8c77ee0a326c112f29d0edf51b7c3e1cd05c4fb92a810177e9c3f12a9?s=96&d=mm&r=g","caption":"scmgalaxy K"},"sameAs":["http:\/\/www.DevOpsSchool.com"],"url":"https:\/\/www.scmgalaxy.com\/tutorials\/author\/scmgalaxy\/"}]}},"_links":{"self":[{"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/posts\/4823","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/comments?post=4823"}],"version-history":[{"count":3,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/posts\/4823\/revisions"}],"predecessor-version":[{"id":4850,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/posts\/4823\/revisions\/4850"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/media\/4848"}],"wp:attachment":[{"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/media?parent=4823"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/categories?post=4823"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/tags?post=4823"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}