How I can access docker data volumes on Windows machine?

Oleksandr Savchenko picture Oleksandr Savchenko · Jun 4, 2017 · Viewed 11.9k times · Source

I have docker-compose.yml like this:

version: '3'
services:
  mysql:
    image: mysql
    volumes:
      - data:/var/lib/mysql
    environment:
      - MYSQL_ROOT_PASSWORD=$ROOT_PASSWORD

volumes:
  data:

And my mount point looks like: /var/lib/docker/volumes/some_app/_data and I want to access data from that mount point and I'm not sure how to do it on Windows machine. Maybe I can create some additional container which can pass data from docker virtual machine to my directory?

When I'm mounting folder like this:

volumes:
  - ./data:/var/lib/mysql

to use my local directory - I had no success because of permissions issue. And read that "right way" is using docker volumes.

UPD: MySQL container it's just example. I want to use such behaviour for my codebase and use docker foe local development.

Answer

Robert picture Robert · Jun 4, 2017

For Linux containers under Windows, docker runs actually over a Linux virtual machine, so your named volume is a mapping of a local directory in that VM to a directory in the container.

So what you got as /var/lib/docker/volumes/some_app/_data is a directory inside that VM. To inspect it you can:

docker run --rm -it -v /:/vm-root alpine:edge ls -l /vm-root/var/lib/docker/volumes/some_app/_data
total 188476
-rw-r-----    1 999      ping            56 Jun  4 04:49 auto.cnf
-rw-------    1 999      ping          1675 Jun  4 04:49 ca-key.pem
-rw-r--r--    1 999      ping          1074 Jun  4 04:49 ca.pem
-rw-r--r--    1 999      ping          1078 Jun  4 04:49 client-cert.pem
-rw-------    1 999      ping          1679 Jun  4 04:49 client-key.pem
-rw-r-----    1 999      ping          1321 Jun  4 04:50 ib_buffer_pool
-rw-r-----    1 999      ping      50331648 Jun  4 04:50 ib_logfile0
-rw-r-----    1 999      ping      50331648 Jun  4 04:49 ib_logfile1
-rw-r-----    1 999      ping      79691776 Jun  4 04:50 ibdata1
-rw-r-----    1 999      ping      12582912 Jun  4 04:50 ibtmp1
drwxr-x---    2 999      ping          4096 Jun  4 04:49 mysql
drwxr-x---    2 999      ping          4096 Jun  4 04:49 performance_schema
-rw-------    1 999      ping          1679 Jun  4 04:49 private_key.pem
-rw-r--r--    1 999      ping           451 Jun  4 04:49 public_key.pem
-rw-r--r--    1 999      ping          1078 Jun  4 04:49 server-cert.pem
-rw-------    1 999      ping          1675 Jun  4 04:49 server-key.pem
drwxr-x---    2 999      ping         12288 Jun  4 04:49 sys

That is running an auxiliar container which has mounted the hole root filesystem of that VM / into the container dir /vm-root.

To get some file run the container with some command in background (tail -f /dev/null in my case), then you can use docker cp:

docker run --name volume-holder -d -it -v /:/vm-root alpine:edge tail -f /dev/null
docker cp volume-holder:/vm-root/var/lib/docker/volumes/volumes_data/_data/public_key.pem .

If you want a transparent SSH to that VM, it seems that is not supported yet, as of Jun-2017. Here a docker staff member said that.