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
Related
Is docker tmpfs working on wsl2.
If I run this in WSL2:
docker run -it --rm -e POSTGRES_PASSWORD=secret --tmpfs /var/lib/postgresql/data postgres:13-alpine sh
The whole container will run in the RAM?
[EDIT]
As #Nik found, tmpfs in WSL is currently mapped to filesystem. At command line level it works as it is mapped in RAM, but it is actually mapped to filesystem. So, take care of this caveat until it is implemented as one would assume.
According to your first question: "Is docker tmpfs working on wsl2?"
it seems the answer is yes. In fact, try to run a container like that:
$ docker run -it --name tmptest --mount type=tmpfs,destination=/mytmp busybox
If you then inspect the container, you can see that /mytmp
is mounted correctly as a tmpfs:
"Mounts": [
{
"Type": "tmpfs",
"Source": "",
"Destination": "/mytmp",
"Mode": "",
"RW": true,
"Propagation": ""
}
]
Some notes about your second question "The whole container will run in the RAM?":
It's just the content of the folder /var/lib/postgresql/data that is stored in RAM,
not the "whole container" whatever you think that means.
It seems to me you're not running the db but a shell instead.
So, unless you start the db from the shell I guess you would have
no particular advantages in having /var/lib/postgresql/data in RAM.
Technically speaking any program has to be loaded in RAM
to work, or at least the portion that is currently executed.
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.
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
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
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.