Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How I can access docker data volumes on Windows machine?

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.

like image 401
Oleksandr Savchenko Avatar asked Jun 04 '17 20:06

Oleksandr Savchenko


People also ask

Where are my docker volumes Windows?

Docker volumes on Windows are always created in the path of the graph driver, which is where Docker stores all image layers, writeable container layers and volumes. By default the root of the graph driver in Windows is C:\ProgramData\docker , but you can mount a volume to a specific directory when you run a container.

How do I find docker volume files?

You can use the docker volume ls command to view a list of data volumes. Use the docker volume inspect command to view the data volume details.

Where is data from docker stored?

They are stored in the part of the host filesystem managed specifically by Docker and it should not be modified by non-Docker processes. Volumes are the most preferred way to store container data as they provide efficient performance and are isolated from the other functionalities of the Docker host.


Video Answer


1 Answers

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.

like image 158
Robert Avatar answered Sep 28 '22 04:09

Robert