Mount docker volume to windows host - docker

I'm running docker for windows on my windows 10 machine (using hyper-v).
If I run the following commands:
docker volume create test
docker volume inspect test
I get:
[
{
"Driver": "local",
"Labels": {},
"Mountpoint": "/var/lib/docker/volumes/test/_data",
"Name": "test",
"Options": {},
"Scope": "local"
}
]
What I want to do is access the path /var/lib/docker/volumes/test/_data from my windows host machine. Is this possible? Maybe by using some other driver instead of local?

You can't access it directly but you can mount and access it
docker run -v test:/vol/test -v ~/mydata:/vol/test2 alpine sh
Now you can access data from host in /vol/test2 and from your volume in /vol/test. Copy anything across that you want

Related

Docker mounting remote volume with sshfs

I know that this question has been done on the web, but I am not able to find a suitable solution for me.
I have one server (VM1) with sshfs installed that should provide remote file system storage. I have another server (VM2) where containers are run, I would like that these containers use volumes hosted in VM1.
I followed this official docker guide
So in VM1 I ran:
docker plugin install vieux/sshfs DEBUG=1 sshkey.source=/home/debian/.ssh/
In VM 2 I ran:
docker volume create --name remotevolume -d vieux/sshfs -o sshcmd=debian#vm1:/home/debian/sshfs300 -o IdentityFile=/home/csicari/data/Mega/lavoro/keys/vm-csicari.key -o -o allow_other -o nonempty
This is the inspect output:
[
{
"CreatedAt": "0001-01-01T00:00:00Z",
"Driver": "vieux/sshfs:latest",
"Labels": {},
"Mountpoint": "/mnt/volumes/895d7f7679f69131500c786d7fe5fdc1",
"Name": "remotevolume",
"Options": {
"IdentityFile": "/home/csicari/data/Mega/lavoro/keys/vm-csicari.key",
"sshcmd": "debian#vm1:/home/debian/sshfs300"
},
"Scope": "local"
}
]
In VM1 I ran also:
docker run -it -v remotevolume:/home -d ubuntu
But I got this error:
docker: Error response from daemon: VolumeDriver.Mount: sshfs command execute failed: exit status 1 (read: Connection reset by peer
). See 'docker run --help'.
Maybe this is a long back asked question maybe it will help other newbies. The remote VM /etc/ssh/sshd_config file content check the property PasswordAuthentication yes
If it is 'yes' we can use with password passing parameter. otherwise, change it to 'no' and restart the ssh or sshd service.
service ssh restart
service ssh status
And also PasswordAuthentication. Depending on your PAM configuration, so check that as well.
If it is AWS instance reset the password using the command passwd ubuntu # Here ubuntu is the default user in ec2 ubuntu instance

How to access the volume in host in docker for windows

I run the docker for Windows and ubuntu in WSL.
When I run the following command
docker volume create test
docker volume inspect test
I get the following output
[
{
"Driver": "local",
"Labels": {},
"Mountpoint": "/var/lib/docker/volumes/test/_data",
"Name": "test",
"Options": {},
"Scope": "local"
}
]
when I access the location, I get
bash: cd: /var/lib/docker/volumes: No such file or directory
So how should I access the folder?
The directory is is protected so you can cd into it, however you can ls the contents:
sudo ls /wsl/docker-desktop-data/data/docker/volumes/test/_data
I've modified my WSL set up as per this article so you may find your path is different. I think the default path is probably /mnt/wsl/docker-desktop-data/data/docker/volumes/test/_data
You might find it more useful to mount a directory in your Windows user folder which can be done by changing the WSL mount point as per the article linked to above and then running:
docker volume create --driver local --name test --opt device=/run/desktop/mnt/host/c/Users/<username>/test --opt type=none --opt o=bind
(assuming you've got a folder called test at the root of your Windows user directory)
based on #nick's answer
From linux: sudo ls /mnt/wsl/docker-desktop-data/data/docker/volumes
From windows: \\wsl$\docker-desktop-data\mnt\wsl\docker-desktop-data\data\docker\volumes
For me the volumes data are at /mnt/wsl/docker-desktop-data/version-pack-data/community/docker/volumes, each distro may mount wsl at different location, this is the default path for Ubuntu at least.
I can cd into it with root permission.

Docker container not mounting data volume

I've got a locally maintained Docker image that, for some reason, is not mounting the local data volume in the container.
docker run -d -v /mnt/melissadata:/usr/local/tomcat/appconf -p 7070:7070 -p 80:8080 --restart on-failure:3 --name addrgeo imagename
On my local data volume, I have a number of files the service needs, but it's unable to find them.
I know the volume is mounted.
$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvdi 202:128 0 10G 0 disk /mnt/melissadata
And it appears that the Docker container can see the volume...
$ docker inspect
...
"Mounts": [
{
"Source": "/mnt/melissadata",
"Destination": "/usr/local/tomcat/appconf",
"Mode": "",
"RW": true,
"Propagation": "rprivate"
}
],
findmnt returns:
$ sudo findmnt -o TARGET,PROPAGATION /mnt/melissadata
TARGET PROPAGATION
/mnt/melissadata private
Any thoughts?
The reason this was happening is because the Docker daemon uses devicemapper to devicemapper to back Docker's layer storage. If the volume was mounted after the Docker daemon was started, then Docker doesn't know it exists. A restart of the Docker daemon fixes it.
sudo service docker restart

Docker volume mount doesn't exist

I'm running Docker 1.11 on OS X and I'm trying to figure out where my local volumes are being written. I created a Docker volume by running docker volume create --name mysql. I then ran docker volume inspect mysql and it output the following:
[
{
"Name": "mysql",
"Driver": "local",
"Mountpoint": "/mnt/sda1/var/lib/docker/volumes/mysql/_data",
"Labels": {}
}
]
The issue is /mnt/sda1/var/lib/docker/volumes/mysql/_data doesn't actually exist on my machine. I thought maybe the issue was that it didn't actually get created until it was used by a container so I started a container by running docker run --name mysql -v mysql:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=mysql -P -d mysql:5.7 and then created a database in MySQL, but the mount point still doesn't exist. I even ran docker inspect mysql to ensure it's using the correct volume and got the following:
...
"Mounts": [
{
"Name": "mysql",
"Source": "/mnt/sda1/var/lib/docker/volumes/mysql/_data",
"Destination": "/var/lib/mysql",
"Driver": "local",
"Mode": "z",
"RW": true,
"Propagation": "rprivate"
}
],
...
At this point I'm completely lost as to where the data is being written. What am I missing?
Because Docker is based on Linux, it cannot run directly on Windows/OS X. Instead, it runs inside a VirtualBox virtual machine (a Docker Machine) that runs a Linux operating system. That's why when you install Docker Toolbox you see that VirtualBox is installed.
To see files and folders inside this virtual machine, use
docker-machine ssh default
default is the name of the default Docker Machine.
Docker 19.3.8
I've changed the mountpoint for a folder that I created in my Mac.
After that it worked.
$ mkdir volume_database
$ docker container run -it \
--volume=/volume_database:/volume_database debian

How to create a shared volume between docker host and container in Mac

I am running DockerHost, docker container on Mac OS X. I have exposed my Mac's /mnt/vol1 (directory) as /mnt_vol1 in the docker container, and it shows up fine. However, the files I write in container volume do not reflect in DockerHost and vice-versa
docker run -it -v /mnt/vol1:/mnt_vol1 --name exposed_volume gopal/ubuntu:v2 /bin/bash
docker inspect showsup correctly:
"Mounts": [
{
"Source": "/mnt/vol1",
"Destination": "/mnt_vol1",
"Mode": "",
"RW": true,
"Propagation": "rprivate"
}
],
Any help is greatly appreciated.

Resources