title: Relative Path with Docker-Compose Shared Volumes
body: <p>It seems <a href="https://stackoverflow.com/questions/42961256/relative-path-not-working-with-named-volumes-in-the-docker-compose-yml">this question has already been asked by another poster</a>, but there was no answer.  I have more information on the matter, so I'm re-asking the same question - but with much additional material.</p>
  
  <p>I'm running Docker on Windows 10.  I have Docker configured for using Linux containers (not Windows containers).  I have my C drive configured as a shared drive.</p>
  
  <h2>The Problem</h2>
  
  <p>I have the following docker-compose file called <code>wp.yml</code>:</p>
  
  <pre><code>version: '3.2'
  
  services:
     db:
       image: mysql:5.7
       volumes:
         - type: volume
           source: wp_dbA
           target: /var/lib/mysql       
       restart: always
  
  volumes:
      wp_dbA:
        driver_opts:
          type: none
          device: ./wp-db
          o: bind
  </code></pre>
  
  <p>I execute as follows:</p>
  
  <pre><code>c:\repos\wpsand\wpA&gt; docker-compose -f wp.yml up -d
  </code></pre>
  
  <p>I receive the following error:</p>
  
  <blockquote>
    <p>ERROR: for wpa_db_1  Cannot create container for service db: error while mounting volume with options: type='none' device='./wp-db' o='bind': no such file or directory</p>
    
    <p>ERROR: for db  Cannot create container for service db: error while mounting volume with options: type='none' device='./wp-db' o='bind': no such file or directory
    ERROR: Encountered errors while bringing up the project.</p>
  </blockquote>
  
  <p>Despite the message,the folder <code>wp-db</code> does already exist, located here:</p>
  
  <pre><code>c:/repos/wpsand/wpA/wp-db
  </code></pre>
  
  <h2>Clues...</h2>
  
  <p>Despite the above error, checking <code>docker volume ls</code> reveals that volume <code>wpa_wp_dbA</code> was freshly created.</p>
  
  <p>Clue #1</p>
  
  <p>If I change the shared volume <code>device</code> to use an absolute path (such as <code>/c/repos/wpsand/wpA</code>), then run again...I get the same problem.  <strong>However</strong>, the error message still says that device with relative path <code>./wp-db</code> cannot be found.  </p>
  
  <p>Apparently the re-use of the shared volume named <code>wp_dbA</code> causes any newly specified path to be ignored.  The original <code>./wp-db</code> is what it will attempt to use.</p>
  
  <p>Clue #2</p>
  
  <p>If I revert back to a relative path, but change the name of the shared volume to "wp_dbB", I still get the same error.</p>
  
  <p>Clue #3</p>
  
  <p>This combines #1 and #2 above.  If I invent a new shared volume name, and use an absolute path, it works!  My container is launched successfully.  Unfortunately, 
   I'm no longer using the relative path I wanted.</p>
  
  <p>Clue #4</p>
  
  <p>Now that my container works, I <code>docker-compose down</code> and change the docker-compose file again.  I put the relative path back in, and "compose up". <strong>It works!</strong></p>
  
  <h2>Conclusion?</h2>
  
  <p>It looks like relative paths simply don't work.  But I've been seeing docker-compose files posted online using this same shared volume relative path notation.  Perhaps it works for Docker, but not Docker on Windows?</p>
  
  <p>Can anyone suggest a work-around?</p>
  
  <h2>Update!</h2>
  
  <p>I found <a href="https://stackoverflow.com/questions/41948232/docker-compose-wont-find-pwd-environment-variable">this SO post</a> that very nearly has a relative-path work-around.  I updated my compose file to use the <code>${PWD}</code> notation, and launched it from my Git Bash shell.  Now I got this error:</p>
  
  <pre><code>$ docker-compose up -d
  Creating wpa_db_1        ... error
  Creating wpa_db_1        ...
  
  ERROR: for wpa_db_1  Cannot create container for service db: error 
  while mounting volume with options: type='none'
  device='C:/repos/wpsand/wpA/wp-db' o='bind': no such file or directory
  
  ERROR: for db  Cannot create container for service db: error while 
  mounting volume with options: type='none' device='C:/repos/wpsand/wpA/wp-db'
  o='bind': no such file or directory
  Encountered errors while bringing up the project.
  </code></pre>
  
  <p>That almost worked!  If only the <code>${PWD}</code> had expanded into a Linux mount notation (<code>/c/repos/wpsand/wpA/wp-db</code>)!</p>