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.
Related
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
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
When creating volumes through the volume API, that is, as the container volume pattern is now not necessarily the best practice anymore:
# docker volume inspect test-data
[
{
"Name": "test-data",
"Driver": "local",
"Mountpoint": "/var/lib/docker/volumes/test-data/_data"
}
]
I would like to, for example, have docker volumes exist in /data (which is mounted in a different physical volume).
This is not possible to do with symbolic links, it is possible to do with bind mounts, but would I'm wondering if there is some configuration in Docker to change the default location for each separate volume.
You can change where Docker stores its files including volumes by changing one of its startup parameters called --data-root.
If you're using systemd for service management, the file is usually located at /lib/systemd/system/docker.service. Edit the file as such:
# Old - taken from the generated docker.service file in Ubuntu 16.04's docker.io package
ExecStart=/usr/bin/dockerd -H fd:// $DOCKER_OPTS
# New
ExecStart=/usr/bin/dockerd --data-root /new_location/ -H fd:// $DOCKER_OPTS
Alternatively, you can edit the Docker daemon configuration file which defaults to /etc/docker/daemon.json.
Restart the Docker daemon and your volumes will be under /new_location/volumes/{volume_name}/_data
Note: be careful in production and also locally! You also have to move the existing data from /var/lib/docker/ to the new location for your docker install to work as expected.
You can use symlinks from the new location if you want specific folders to be in specific place.
2017: with 17.05.0-ce (2017-05-04), the PR 28696 deprecates --graph flag in favor or --data-root: commit 1ecaed0
The name "graph" is a legacy term from long ago when there used to be a directory at the default location /var/lib/docker/graph.
However, the flag would indicate the path of the parent directory of the "graph" directory which contains not only image data but also data for volumes, containers, and networks.
In the most recent version of docker, this directory also contains swarm cluster state and node certificates.
With issue 5922 and PR 5978, the documentation has been updated.
Example:
ExecStart=/usr/bin/dockerd -H fd:// --data-root=/mnt/ssd/lib/docker
2016 (now deprecated)
I only know of a docker option to change /var/lib/docker itself, not its subfolders (part of its "graph" used by a docker daemon storage driver)
See docker daemon "Miscellaneous options":
Docker supports softlinks for the Docker data directory (/var/lib/docker) and for /var/lib/docker/tmp.
The DOCKER_TMPDIR and the data directory can be set like this:
DOCKER_TMPDIR=/mnt/disk2/tmp /usr/local/bin/docker daemon -D -g /var/lib/docker -H unix:// > /var/lib/docker-machine/docker.log 2>&1
# or
export DOCKER_TMPDIR=/mnt/disk2/tmp
/usr/local/bin/docker daemon -D -g /var/lib/docker -H unix:// > /var/lib/docker-machine/docker.log
As mentioned in "Where are docker images stored on the host machine?" (and that would apply also for containers/volumes):
The contents of the /var/lib/docker directory vary depending on the driver Docker is using for storage.
I successfully moved the storage location of docker by moving the content of /var/lib/docker to a new location and then place a symlink pointing to the new location (I took this solution from here https://askubuntu.com/questions/631450/change-data-directory-of-docker):
Caution - These steps depend on your current /var/lib/docker being an
actual directory (not a symlink to another location).
1) Stop docker: service docker stop. Verify no docker process is running:
ps aux | grep -i [d]ocker
2) Double check docker really isn't running. Take a look at the current docker directory:
ls /var/lib/docker/
2b) Make a backup - tar -zcC /var/lib docker >
/mnt/pd0/var_lib_docker-backup-$(date +%s).tar.gz
3) Move the /var/lib/docker directory to your new partition:
mv /var/lib/docker /mnt/pd0/docker
4) Make a symlink: ln -s /mnt/pd0/docker /var/lib/docker
5) Take a peek at the directory structure to make sure it looks like
it did before the mv: ls /var/lib/docker/ (note the trailing slash)
6) Start docker back up service docker start
7) restart your containers (resolve the symlink)
Worked for me on Ubuntu 18.04.1 LTS on an Azure VM with Docker 18.09.2
If you're on Fedora (tested on 32) just change or add the --data-root flag with your desired path to the OPTIONS variable on /etc/sysconfig/docker, this is the environment file used by systemd to start the dockerd service.
I have a directory(maybe later volume), that I would like to share with all my interactive containers. I know, that native Docker volumes are stored under /var/lib/docker/volumes and docker run -v seems the easiest way, but I think Data Volume Container is a much more standardized way. I don't know, how to create this volume container from a directory or an existing another volume. Maybe is it wrong method?
There are two ways to create and share volumes: 1. using the VOLUME instruction on the Dockerfile. 2 Specifying the -v <volume_name> option during container runtime and later using --volumes-from=<container> with every subsequent container which need to share the data. Here is an ex with the later:
Start your first container with -v, then add a test file under the directory of the shared volume.
docker run -it -v /test-volume --name=testimage1 ubuntu:14.04 /bin/bash
root#ca30f0f99401:/# ls
bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys test-volume ===> test-volume dir got created here
root#ca30f0f99401:/# touch test-volume/1
root#ca30f0f99401:/# cat > test-volume/1
Test Message!
From the host OS, you can get details of the volume by inspecting your container:
docker inspect ca30f0f99401 | grep -i --color -E '^|Vol'
"Mounts":
{
"Name": "025835b8b47d282ec5f27c53b3165aee83ecdb626dc36b3b18b2e128595d9134",
"Source": "/var/lib/docker/volumes/025835b8b47d282ec5f27c53b3165aee83ecdb626dc36b3b18b2e128595d9134/_data",
"Destination": "/test-volume",
"Driver": "local",
"Mode": "",
"RW": true
"Image": "ubuntu:14.04",
"Volumes": {
"/test-volume": {} }
Start another container with a shared volume and check if the shared folder/files exists.
$ docker run -it --name=testimage2 --volumes-from=testimage1 ubuntu:14.04 /bin/bash
root#60ff1dcebc44:/# ls
bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys test-volume tmp usr var
root#60ff1dcebc44:/# cat test-volume/1
Test Message!
Goto step-3 to share volume with a new container.
Make a data volume container by writing a dedicated Dockerfile in which you would:
COPY your folder in it
declare that copied local container path folder as a VOLUME
Then docker create <imagename> and you get a (created) container, that you can mount in all your other containers, provided you run them with the --volumes-from <containername> option.
So, despite Docker 1.3 now allowing easy access to external storage on OSX through boot2docker for files in /Users/, I still need to access files not in /Users/. I have a settings file in /etc/settings/ that I'd like my container to have access to. Also, the CMD in my container writes logs to /var/log in the container, which I'd rather have it write to /var/log on the host. I've been playing around with VOLUME and passing stuff in with -v at run, but I'm not getting anywhere. Googling hasn't been much help. Can someone who has this working provide help?
As boot2docker now includes VirtualBox Guest Additions, you can now share folders on the host computer (OSX) with guest operating systems (boot2docker-vm). /Users/ is automatically mounted but you can mount/share custom folders. In your host console (OSX) :
$ vboxmanage sharedfolder add "boot2docker-vm" --name settings-share --hostpath /etc/settings --automount
Start boot2docker and ssh into it ($boot2docker up / $boot2docker ssh).
Choose where you want to mount the "settings-share" (/etc/settings) in the boot2docker VM :
$ sudo mkdir /settings-share-on-guest
$ sudo mount -t vboxsf settings-share /settings-share-on-guest
According that /settings is the volume declared in the docker container add -v /settings-share-on-guest:/settings to the docker run command to mount the host directory settings-share-on-guest as a data volume.
Works on Windows, not tested on OSX but should work.