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

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

Related

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

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

The mounting a folder to a Docker image remains indefinitely stuck

I'm trying to mount a folder to a docker image in Ubuntu 20.04:
(base) raphy#pc:~$ sudo docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.tigergraph.com/tigergraph latest 6c55bb15e2a6 7 days ago 10.6GB
hello-world latest feb5d9fea6a5 6 weeks ago 13.3kB
(base) raphy#pc:~$ sudo docker run -t -i -v /home/raphy/ConceptNet/ 6c55bb15e2a6
It doesn't give any error, but it remains indefinitely stuck
Update 1)
(base) raphy#pc:~$ sudo docker run -t -i -v /home/raphy
/ConceptNet:/6c55bb15e2a6/ConceptNet bash
Unable to find image 'bash:latest' locally
latest: Pulling from library/bash
a0d0a0d46f8b: Pull complete
ae2d64a5f3ef: Pull complete
1e5367194cc8: Pull complete
Digest:
sha256:91767623eb341f1717bb37b059e77e8de439c8044064808f6f9bfdc942e8d30c
Status: Downloaded newer image for bash:latest
bash-5.1# ^C
What am I doing wrongly?
SOLVED in this way:
(base) raphy#pc:~$ sudo docker run -d -p 14022:22 -p 9000:9000 -p
14240:14240 --name tigergraph --ulimit nofile=1000000:1000000 -v
~/ConceptNet/:/home/tigergraph/myconceptnet -t
docker.tigergraph.com/tigergraph:latest
https://docs.tigergraph.com/start/get-started/docker#2.-prepare-a-shared-folder-on-host-os-to-be-shared-with-docker-container
Your docker command is insufficient to run tigergraph... it's not a simple run command will do, follow the instruction at https://docs.tigergraph.com/start/get-started/docker
your intention is to bind a local path on your host to your container, but what you are really doing now is attaching a new local empty volume to /home/raphy/ConceptNet/ on your container, just exec:
docker exec {your container id} ls /home/raphy/ConceptNet/
to see the path is created inside your container.
also you can use:
docker inspect {your container id} | less
and check the "Mounts" part to see what volumes you have really attached to your container, the output will be something like:
"Mounts": [
{
"Type": "volume",
"Name": "43f6d9846728547b77666705d2b5a4be1d1e644af80f3bb53d86fe105f57bfc6",
"Source": "/var/lib/docker/volumes/43f6d9846728547b77666705d2b5a4be1d1e644af80f3bb53d86fe105f57bfc6/_data",
"Destination": "/home/raphy/ConceptNet/",
"Driver": "local",
"Mode": "",
"RW": true,
"Propagation": ""
}
],
while
"Name": "43f6d9846728547b77666705d2b5a4be1d1e644af80f3bb53d86fe105f57bfc6"
is the name of the volume you've unintentionally created and attached on path /home/raphy/ConceptNet/ in your container.
if you want to mount a local directory to your container, just use:
sudo docker run -t -i -v /home/raphy/ConceptNet/:/some_path/ 6c55bb15e2a6
and if you want to have shell inside your container its better to include your command at the end of docker run like:
sudo docker run -t -i -v /home/raphy/ConceptNet/:/some_path/ 6c55bb15e2a6 /bin/sh
Try this
-v, --volume=[host-src:]container-dest[:<options>]:
Reference Link

Cant get docker run -v to work

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

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