I'm using docker 1.13.1 in Windows 10 with Hyper-v
and I've a volume
C:\autotestDocker\plat1>docker inspect plat1_logscore
[
{
"Driver": "local",
"Labels": {
"com.docker.compose.project": "plat1",
"com.docker.compose.volume": "logscore"
},
"Mountpoint": "/var/lib/docker/volumes/plat1_logscore/_data",
"Name": "plat1_logscore",
"Options": {},
"Scope": "local"
}
]
Is it possible to found in the filesystem the "Mountpoint" directly?
I cannot change the mount method (I cannot mount it to another folder), I have these settings and I cannot change them...
I've tried with an ubuntu machine and if I try to do
cd /var/lib/docker/volumes/plat1_logscore/_data
I can modify or copy file inside the correct volume.
I would do the same with windows, but I'm just not able to locate the mount directory
You can mount the volume in another container and modify it from there.
docker run -it --rm -v plat1_logscore:/target ubuntu
Select whatever image you'd like to use in place of ubuntu. Then your plat1_logscore volume will be accessible under /target and you can edit it with any commands included inside of your container.
Alternatively, you can copy the files out to your host with a command like:
docker run -it --rm -v plat1_logscore:/source \
-v c:/Users/Marco/plat1_logscore:/target \
busybox cp -avr /source/. /target/.
You can reverse the volumes in the command to copy files back into your named volume from your host.
Related
I put one security file like id_rsa in the docker volume larrycai_vol, trying to mount this into the container as a file.
$ docker volume inspect larrycai-vol
[
{
"CreatedAt": "2018-05-18T06:02:24Z",
"Driver": "local",
"Labels": {},
"Mountpoint": "/var/lib/docker/volumes/larrycai-vol/_data",
"Name": "larrycai-vol",
"Options": {},
"Scope": "local"
}
]
Do we have some command like below (it doesn't work now)
docker run -it -v larrycai-vol/id_rsa:/root/.ssh/id_rsa own_ubuntu
I know it works if I mount file from docker host
docker run -it -v $PWD/.ssh/id_rsa:/root/.ssh/id_rsa own_ubuntu
Please, let me a couple of considerations furthermore the proposed solution to avoid further misunderstandings.
Docker allows mounting volumes (deployed from path dir of your host to docker path, i.e, -v $PWD/.ssh:/root/.ssh = it'd replace complete .ssh folder in destination, so, it's not recommended although possible)
Docker allows mounting named volumes (deployed from named volume name to docker path, i.e, -v larrycai-vol:/root/.ssh = it'd replace complete .ssh folder in destination, so, it's not recommended although possible)
Docker allows mounting files from host to a docker (example: -v $PWD/.ssh/id_rsa:/root/.ssh/id_rsa = your second example)
Docker allows mounting files from named volume to a docker (example: -v /var/lib/docker/volumes/YOUR_NAMED_VOLUME_NAME/_data/file:/dest_dir/file = what you're trying to do)
Your mistake is that you're telling docker to mount id_rsa from your larrycai-vol directory, not from docker named volume.
In other words, three following commands are equivalent:
docker run -it -v ./larrycai-vol/id_rsa:/root/.ssh/id_rsa own_ubuntu
docker run -it -v $PWD/larrycai-vol/id_rsa:/root/.ssh/id_rsa own_ubuntu
docker run -it -v larrycai-vol/id_rsa:/root/.ssh/id_rsa own_ubuntu
So, if larrycai-vol directory (not named volume, but directory in your host) doesn't exist, command doesn't work as you want.
Definitively, to do what you're trying you have to create a bind volumeto the directory where named volume store data.
docker run -it -v
/var/lib/docker/volumes/larrycai-vol/_data/id_rsa:/root/.ssh/id_rsa
own_ubuntu
I want the /home/moodle folder on the host to be the same as the /var/www/html folder in the container.
I tried running this command:
sudo docker run -d -P --name moodle --link DB:DB -p 8080:80 -v /home/moodle:/var/www/html jhardison/moodle
It adds this to docker inspect:
"Mounts": [
{
"Type": "bind",
"Source": "/home/moodle",
"Destination": "/var/www/html",
"Mode": "",
"RW": true,
"Propagation": ""
},
But the /home/moodle folder is empty and not the same as /var/www/html in the container
Here an extract from the docker documentation
docker run -d -P --name web -v /src/webapp:/webapp training/webapp python app.py
This command mounts the host directory, /src/webapp, into the
container at /webapp. If the path /webapp already exists inside the
container’s image, the /src/webapp mount overlays but does not remove
the pre-existing content. Once the mount is removed, the content is
accessible again. This is consistent with the expected behavior of the
mount command.
Mounting a empty folder will overlay whatever contents your container had at that folder. For sharing data from within a container you could mount your folder to some empty directory and let your application copy data into that directory or run bash commands from your container to do the same as described in another thread:
docker exec -it mycontainer /bin/bash
Or you could use docker copy as described in another stackoverflow thread:
docker cp <containerId>:/file/path/within/container /host/path/target
If you mount a host directory in an image directory that previously exited, the content of the image directory is not removed, but the content of your host directory will also be in your container directory.
Take a look to Docker docs to further information: https://docs.docker.com/engine/tutorials/dockervolumes/#mount-a-host-directory-as-a-data-volume
I have a docker file that looks like this. How can I access this volume from the host? I checked the volumes folder where Docker is installed.
FROM busybox
MAINTAINER Erik Kaareng-sunde <esu#enonic.com>
RUN mkdir -p /enonic-xp/home
RUN adduser -h /enonic-xp/ -H -u 1337 -D -s /bin/sh enonic-xp
RUN chown -R enonic-xp /enonic-xp/
VOLUME /enonic-xp/home
ADD logo.txt /logo.txt
CMD cat /logo.txt
ls
$ docker volume ls
DRIVER VOLUME NAME
local b4e99290fd4d5f7a3fe700ae9b616c2e66b1f758c497662415cdb47905427719
I would like to be able to cd into that volume.
inspect
docker volume inspect b4e99290fd4d5f7a3fe700ae9b616c2e66b1f758c497662415cdb47905427719
[
{
"Driver": "local",
"Labels": null,
"Mountpoint": "/var/lib/docker/volumes/b4e99290fd4d5f7a3fe700ae9b616c2e66b1f758c497662415cdb47905427719/_data",
"Name": "b4e99290fd4d5f7a3fe700ae9b616c2e66b1f758c497662415cdb47905427719",
"Options": {},
"Scope": "local"
}
]
After looking at a lot of posts, I finally found a post that address the question asked here.
Getting path and accessing persistent volumes in Docker for Mac
Note: this works only for Mac.
The path for the tty may also be present here:
~/Library/Containers/com.docker.docker/Data/vm/*/tty
Instead of doing it within the dockerfile, you can simply mount with docker run -v /path/in/host:/path/in/container image-name....
Docker volume ls lists all volumes docker volume inspect lets you inspect a volume. If you cant find your volume with docker volume ls try docker inspect your container and check for info there
I'm using Docker for mac and I want to find where are the volume created by Docker.
# Create volume
docker volume create --name volume-name
# Create container binding this volume
docker run -dti -v volume-name:/data --name deb debian:jessie
# Create a file in container:/data
docker exec -ti deb touch /data/test.txt
# Find the Mountpoint
docker volume inspect volume-name
# Get :
# [
# {
# "Name": "volume-name",
# "Driver": "local",
# "Mountpoint": "/var/lib/docker/volumes/volume-name/_data",
# "Labels": {},
# "Scope": "local"
# }
# ]
When I am using Docker on Linux, I can run
ls /var/lib/docker/volumes/volume-name/_data
and see the test.txt file
But, on macOs I don't know where I can find this Mountpoint.
I found this post (Docker volume mount doesn't exist) but the author seems to use boot2docker and I'm not.
docker-machine ssh default
# Host does not exist: "default"
Can someone help me to find this Mountpoint on macOs using Docker for Mac
I finally found the solution to get access of the linux virtual machine using docker for mac
sudo screen ~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/tty
cd /var/lib/docker/volumes/volume-name/_data
mv test.txt /Users/path/to/destination
By default some directories are shared (/Users, /Volumes, ...), Then I can move my data volume directory to my mac from the vm.
I have a Docker Image which has a VOLUME ["/log"].
While running the container I am mounting a folder present on the host.
I want all the logs written by docker at VOLUME ["/log"] to be available to the host.
docker run --name=test -v ${pwd}/hostlogfolder:/log dockerimage:1
The logs are not getting written to by hostlogfolder
But the logs are available inside docker at location /log
docker exec -it test bash
cd /log
What is the correct way to mount the folder?
You are almost there, the command needs a small correction:
docker run --name=test -v $(pwd)/hostlogfolder:/log dockerimage:1
Note that the brackets are different:
wrong: ${pwd}
right: $(pwd)
Once running, you can verify the mounted volumes using:
docker inspect <container id> -- you can get the container id using docker ps
Check the Mounts section of the command output.
"Mounts": [
{
"Source": "<host path>",
"Destination": "<container path>",
"Mode": "",
"RW": true
}]
If you want to create an image with predefined settings like add volume, then you have to use Dockerfile. Or, if you don't need to create an image, but only need a temporary container to pass it when you create a container.
I think you need to read the documentation about creating volumes and other directives. It might be very useful for you.
docker run -d -P --name web -v /webapp training/webapp python app.py
https://docs.docker.com/engine/userguide/containers/dockervolumes/