title: Can we mount sub-directories of a named volume in docker?
body: <p>The docker-compose file <a href="https://docs.docker.com/compose/compose-file/#/volumes-volume-driver" rel="noreferrer">https://docs.docker.com/compose/compose-file/#/volumes-volume-driver</a> shows various ways to mount host sub-directories relative to the compose file.</p>
  <p>For example:</p>
  <pre class="lang-yaml prettyprint-override"><code>volumes:
     # Just specify a path and let the Engine create a volume
     - /var/lib/mysql
   
     # Specify an absolute path mapping
     - /opt/data:/var/lib/mysql
   
     # Path on the host, relative to the Compose file
     - ./cache:/tmp/cache
   
     # User-relative path
     - ~/configs:/etc/configs/:ro
   
     # Named volume
     - datavolume:/var/lib/mysql
  </code></pre>
  <p>Is is possible to mount a sub-directory of a named volume at a specific location?  For example something like below, which I tried, but does not seem to work.</p>
  <pre><code># Named volume
    - datavolume/sql_data:/var/lib/mysql
  </code></pre>
  <p>I am assuming I might be able to manage this by mounting the data volume to a location like <code>/data</code> and then in the Dockerfiles for each container, create symbolic links from the sub-directories to the locations.</p>
  <p>for example in a docker-compose.yml file</p>
  <pre><code>volumes:
    - datavolume:/data
  </code></pre>
  <p>and then in the container Dockerfile</p>
  <pre><code>RUN ln -s /data/sql_data /var/lib/mysql
  </code></pre>
  <p>I started going down this path but it was getting messy and was not working.  Before I either abandon that approach or invest the time debugging it, I wanted to make sure there was no way to just specify sub-directories of a named vollume.</p>