title: Copy data from docker-compose auto-created volume to new external volume
body: <p>When you use a volume in <code>docker-compose</code>, <code>docker</code> will create a volume with the volume name appended to the directory name: <code>[directory containing yml]_[volume name]</code></p>
  <p><code>/var/containers/my-important-server-v0.23/docker-compose.yml</code></p>
  <pre class="lang-yml prettyprint-override"><code>volumes:
      server-db:
      # Volume name: my-important-server-v0.23_server-db
  </code></pre>
  <p>Now when you move and rename the directory containing <code>docker-compose.yml</code> for reasons, it will create a new volume with the new directory prepended to the volume name.</p>
  <p>In order to prevent this, and allow multiple compose files to use the same volume, we should have created a volume manually:</p>
  <p><code>docker volume create server-db</code></p>
  <pre class="lang-yml prettyprint-override"><code>volumes:
      server-db:
          external: true
  </code></pre>
  <p>How can we transfer the files from <code>my-important-server-v0.23_server-db</code> to <code>server-db</code>?</p>
  <hr />
  <p>This is what I tried and seemed to make sense, but it doesn't work as expected.</p>
  <pre class="lang-sh prettyprint-override"><code>docker volume create server-db
  OLD=$(docker volume inspect my-important-server-v0.23_server-db | jq -r .[0].Mountpoint)
  NEW=$(docker volume inspect server-db | jq -r .[0].Mountpoint)
  sudo rsync -va $OLD/ $NEW/
  </code></pre>
  <p>Now here is the problem. The directory containing MariaDB files have different sizes. Apparently you can't simply copy the files like that.</p>