Docker Container volume bind's data not appearing in the volume - docker

i'm trying to mount an existing directory that has images and subsequent images will be stored into it. I need to use that local directory to mount to a docker container.
When entering this command, it is successful, but there is no data inside. Any help would be appreciated. Thank you~!
docker volume create --name my_test_volume --opt type=none --opt device=/localdrive/myfolder/simplehttpserver/images --opt o=bind
Docker volume inspect
[
{
"CreatedAt": "2022-10-29T09:23:48Z",
"Driver": "local",
"Labels": {},
"Mountpoint": "/datadrive/docker/volumes/my_test_volume/_data",
"Name": "my_test_volume",
"Options": {
"device": "/localdrive/myfolder/simplehttp/images",
"o": "bind",
"type": "none"
},
"Scope": "local"
}
]
I've tried to restart the docker daemon with sudo service docker but to no avail after creating the volume.
Doing a sudo ls in the directory volume directory in Docker directory
sudo ls

Related

Docker Run Permission Issue while setting up volume

I have created a folder my-jenkins-data and changed the permission to chown -R 1000 /root/my-jenkins-data but I get a "permission denied" error when I try to access the bind-mounted directory from a container.
Here is the quick snippet of the command:
[root#osboxes /]# sudo chown -R 1000 /root/my-jenkins-data
[root#osboxes /]# sudo docker run -p 8080:8080 -v /root/my-jenkins-data:/var/jenkins_home jenkins/jenkins:lts
touch: cannot touch '/var/jenkins_home/copy_reference_file.log': Permission denied
Can not write to /var/jenkins_home/copy_reference_file.log. Wrong volume permissions?
Jenkins has non-root user that is jenkins.
Try to run
chown -R 1000:1000 /root/my-jenkins-data
Or you can give all permissions to the folder.
chmod -R 777 /root/my-jenkins-data
Or you can create docker volume and attach to Jenkins.
docker volume create jenkins
docker run -p 8033:8080 -v jenkins:/var/jenkins_home -u root jenkins/jenkins:lts
To list volume folder execute get folder location with docker volume inspect jenkins
$ docker volume inspect jenkins
[
{
"CreatedAt": "2021-01-02T22:13:07+03:00",
"Driver": "local",
"Labels": {},
"Mountpoint": "/var/lib/docker/volumes/jenkins/_data",
"Name": "jenkins",
"Options": {},
"Scope": "local"
}
]
$ ls /var/lib/docker/volumes/jenkins/_data

Mounted volume is always empty on container machine on mac/lunux

I am trying to run docker container with some files that I want to share with container machine from the host machine.
For example, I want to share my ~/Desktop folder with container machine. I am running:
$ docker run -it -v ~/Desktop:/Desktop r-base bash
then when I do ls -la /Desktop on container machine it does not show any files even if I have some on my host machine.
When I do docker inspect <container_id> it shows my mounts as:
},
"Mounts": [
{
"Type": "bind",
"Source": "/Users/user/Desktop",
"Destination": "/Desktop",
"Mode": "",
"RW": true,
"Propagation": "rprivate"
}
],
My docker version:
$ docker --version
Docker version 19.03.1, build 74b1e89
$ docker-machine --version
docker-machine version 0.16.1, build cce350d

What is the host-src if it's not specified in docker run -v

I have a jenkins docker container
which I am running like
docker run -p 8080:8080 -p 50000:50000 -v /var/jenkins_home jenkins
Now I killed the container and when I ran the same command it's not fetching the data.
Now when I am not specifying the host-src what does it usually ?
Shouldn't it throw an error ?
docker will create the volume under /var/lib/docker/volumes/if you not specify the source
you can list your volumes:
docker volume ls
and see where it is:
docker inspect <NAME_FROM_PREVIOUS_COMMAND>
output will be something like:
[
{
"CreatedAt": "2019-07-31T12:06:49Z",
"Driver": "local",
"Labels": null,
"Mountpoint": "/var/lib/docker/volumes/802042a3d5bd336a068ad3c349f7f9e9c9c0ddd5e21b550c57bea4b16625cb86/_data",
"Name": "802042a3d5bd336a068ad3c349f7f9e9c9c0ddd5e21b550c57bea4b16625cb86",
"Options": null,
"Scope": "local"
}
]

Docker volume access from host

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

docker volume mount directory in windows

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.

Resources