What is preventing file persistence when using a Docker volume? - docker

I have a Docker image named pfa-image (contains a fairly basic Express-based website), a running mongoDB container named pfa-mongo, and a docker volume named image-volume. When I run the following sequence of commands..:
host$ docker run -d --name pfa-container -v image-volume:/images \
--link pfa-mongo:mongodb -p 5000:5000 pfa-image
host$ docker exec -it pfa-container /bin/bash
container:/pfa-site# cd images
container:/pfa-site/images# touch test.txt
container:/pfa-site/images# exit
host$ docker rm -f pfa-container
host$ docker run -d --name pfa-container -v image-volume:/images \
--link pfa-mongo:mongodb -p 5000:5000 pfa-image
host$ docker exec -it pfa-container /bin/bash
container:/pfa-site# cd images
container:/pfa-site/images# ls
...test.txt is missing. What am I overlooking here? I am quite new to docker and somewhat new to Linux.
Thank you!
I have tried using bind mounts and volumes, to the same result.

Related

How to create a Debian docker container that can run docker containers?

I need a Debian container that can run containers itself (and has access to systemd). Following this post, I have tried to run
docker run -v /var/run/docker.sock:/var/run/docker.sock --name debian-buster-slim -h 10-slim -e LANG=C.UTF-8 -it debian:10-slim /bin/bash -l
but the container cannot run docker containers. What am I doing wrong?

Cannot share data between volumes on different containers on Jenkins

I am new at docker and I've been struggling with the following:
sh "docker network create grid${buildProperties}"
sh "docker run -d --net grid${buildProperties} --health-cmd=\"curl -sSL http://selenium-hub${buildProperties}:4444/wd/hub/status | jq -r '.status' | grep 0\" --health-interval=5s --health-timeout=1s --health-retries=10 --name selenium-hub${buildProperties} selenium/hub:3.141.59-radium"
sh "docker run -d --link selenium-hub${buildProperties}:selenium-hub --net grid${buildProperties} -e HUB_HOST=selenium-hub -v /dev/shm:/dev/shm --name chrome-node${buildProperties} selenium/node-chrome:3.141.59-20200525"
sh "docker build -t ui-tests-runner ."
sh "docker run -d --link selenium-hub${buildProperties}:selenium-hub --net grid${buildProperties} -e HUB_HOST=http://selenium-hub:4444/wd/hub -v DataVolume5:/src --name ui-tests-runner${buildProperties} ui-tests-runner"
sh "docker ps"
sh "docker run --rm -v DataVolume5:/datavolume5 ubuntu ls -l datavolume5"
I am trying to get data from ui-tests-runner${buildProperties} container from /src into DataVolume5
I am getting 0 files when I list the contents of datavolume5
However, if I try to do the same thing with chrome-node${buildProperties} /home I can see /seluser when I list the contents of datavolume5 which is expected.
sh "docker network create grid${buildProperties}"
sh "docker run -d --net grid${buildProperties} --health-cmd=\"curl -sSL http://selenium-hub${buildProperties}:4444/wd/hub/status | jq -r '.status' | grep 0\" --health-interval=5s --health-timeout=1s --health-retries=10 --name selenium-hub${buildProperties} selenium/hub:3.141.59-radium"
sh "docker run -d --link selenium-hub${buildProperties}:selenium-hub --net grid${buildProperties} -e HUB_HOST=selenium-hub -v /dev/shm:/dev/shm -v DataVolume5:/seluser --name chrome-node${buildProperties} selenium/node-chrome:3.141.59-20200525"
sh "docker build -t ui-tests-runner ."
sh "docker run -d --link selenium-hub${buildProperties}:selenium-hub --net grid${buildProperties} -e HUB_HOST=http://selenium-hub:4444/wd/hub --name ui-tests-runner${buildProperties} ui-tests-runner"
sh "docker ps"
sh "docker run --rm -v DataVolume5:/datavolume5 ubuntu ls -l datavolume5"
I tried numerous things that I found online, I checked permissions and that seems fine. The only thing I can think of what's different is that the ui-tests-runner${buildProperties} container is hosting a repository. I don't know what else to try. I have been struggling for a few days now.
This piece of code was taken from the pipeline bit in the Jenkinsfile
You have a race condition between these two commands:
sh "docker run -d ... -v DataVolume5:/src ... ui-tests-runner"
sh "docker run --rm -v DataVolume5:/datavolume5 ubuntu ls -l datavolume5"
The first command, with the -d option, will not stop. It will run the container in the background. The second command then runs while your ui-tests-runner container is starting up, and shows the folder before your tests have run.
Named volumes are also populated when first used with the image contents at that location. So when you use a different path that has contents inside your image at that location, you'll get files in the volume.
Once that initialization step is done and the volume is no longer empty, you'll only see files that are written to the volume by the process inside a container. You won't get changes from the image filesystem as images are redeployed since that path in the container is replaced by the contents of the persistent volume.
I presume you're creating DataVolume5 as a named volume, using
docker volume create.
In which case you don't need to specify the absolute path, but docker volume inspect DataVolume5 will give you the path.
Try using a specific host directory as the shared volume instead.
docker run -d -v myVolume:/src ui-tests-runner
first check DataVolume5 containes something after running ui-tests-runner command
in the command docker run --rm -v DataVolume5:/datavolume5 ubuntu ls -l datavolume5
give absolute path of DataVolume5
Eg. docker run --rm -v /abs-path-to-directory/DataVolume5:/datavolume5 ubuntu ls -l datavolume5

Unable to backup docker volumne

I'm following the offical docker guide from here to backup a docker volume. I'm also aware of this SO question however I'm still running into errors. Running the following command:
docker run --rm --volumes-from dbstore -v $(pwd):/backup ny_db_1 tar cvf /backup/backup.tar /dbdata
No matter what image name or container name or container id I put, I get the following error:
Unable to find image 'ny_db_1:latest' locally
The volume I want to backup:
$ docker volume ls
DRIVER VOLUME NAME
local ny_postgres_data
My containers:
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
39e71e660eda postgres:10.1-alpine "docker-entrypoint.s…" 4 days ago Up 23 minutes 0.0.0.0:5434->5433/tcp ny_db_1
How do I backup my volume?
Update:
I tried the following but ran into a new error:
$ docker run --rm --volumes-from 39e71e660eda -v $(pwd):/backup postgres:10.1-alpine tar:local cvf /backup/backup.tar /dbdata
/usr/local/bin/docker-entrypoint.sh: line 145: exec: tar:local: not found
The docker run syntax is docker run [OPTIONS] IMAGE[:TAG|#DIGEST] [COMMAND] [ARG...] - ny_db_1 is the name of your container, docker will attempt to use the IMAGE "ny_db_1" which does not exist hence the error: "Unable to find image 'ny_db_1:latest' locally" (latest is the default [:TAG] if none is specified).
--volumes-from will mount volumes from the specified container(s) into a new container spawned from IMAGE[:TAG] for example: docker run --rm --volumes-from db -v $(pwd):/backup ubuntu:18.04 tar czvf /backup/backup.tar /dbdata
Note: if you're backing up a PostgreSQL database then imho you'd be better off using the appropriate tools to backup and restore the database for example:
Backup using pg_dumpall:
docker run --rm \
--name db-backup \
--entrypoint pg_dumpall \
--volume ${PWD}/backup:/backup \
--volumes-from db \
postgres:9 --host /var/run/postgresql --username postgres --clean --oids --file /backup/db.dump
Restore using psql:
docker run --rm -it \
-v ${PWD}/backup:/restore \
--name restore \
postgres:10.1-alpine
docker exec restore psql \
--host /var/run/postgresql \
--username postgres \
--file /restore/db.dump postgres
docker rename restore NEW_NAME
try this command here:
docker run -it --rm -v ny_postgres_data:/volume -v /tmp:/backup ny_db_1 \
tar -cjf /backup/ny_postgres_data -C /volume ./

Can we run docker inside a docker container which is running in a virtual-box of Ubuntu 18.04?

I want to run docker inside another docker container. My main container is running in a virtualbox of OS Ubuntu 18.04 which is there on my Windows 10. On trying to run it, it is showing me as:
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
How can I resolve this issue?
Yes, you can do this. Check for dind (docker in docker) on docker webpage how to achieve it: https://hub.docker.com/_/docker
Your error indicates that either dockerd in the top level container is not running or you didn't mount docker.sock on the dependent container to communicate with dockerd running on your top-level container.
I am running electric-flow in a docker container in my Ubuntu virtual-box using this docker command: docker run --name efserver --hostname=efserver -d -p 8080:8080 -p 9990:9990 -p 7800:7800 -p 7070:80 -p 443:443 -p 8443:8443 -p 8200:8200 -i -t ecdocker/eflow-ce. Inside this docker container, I want to install and run docker so that my CI/CD pipeline in electric-flow can access and use docker commands.
From your above description, ecdocker/eflow-ce is your CI/CD solution container, and you just want to use docker command in this container, then you did not need dind solution. You can just access to a container's host docker server.
Something like follows:
docker run --privileged --name efserver --hostname=efserver -d -p 8080:8080 -p 9990:9990 -p 7800:7800 -p 7070:80 -p 443:443 -p 8443:8443 -p 8200:8200 -v $(which docker):/usr/bin/docker -v /var/run/docker.sock:/var/run/docker.sock -i -t ecdocker/eflow-ce
Compared to your old command:
Add --privileged
Add -v $(which docker):/usr/bin/docker, then you can use docker client in container.
Add -v /var/run/docker.sock:/var/run/docker.sock, then you can access host's docker daemon using client in container.

How can I save zeppelin notebook from a docker?

I am using a docker-container for spark-zeppelin. The docker image was fund here,
https://github.com/Gmousse/docker-zeppelin-python3
I can start an image and work using this command,
docker run -it -p 8080:8080 -p 8081:8081 gmousse/docker-zeppelin-python3
To be able to communicate with the host, I have mounted some paths to host with volume flag like this,
docker run -it -v /cephfs:/cephfs -p 8080:8080 -p 8081:8081 gmousse/docker-zeppelin-python3
it works fine. Now to mount the zeppelin working directory I added this,
docker run -it -v /cephfs:/cephfs -v my_path_on_host:/zeppelin -p 8080:8080 -p 8081:8081 gmousse/docker-zeppelin-python3
And this does not run.
In this command actually it is looking for a zeppelin.sh file in /zeppelin and fails.
Any idea, how can I mount a local volume, and be able to save zeppelin notebook on the host?
Thank you for your time, in advance...
It is very handy to store notebooks on local file system especially under version control.
So you need to mount only notebook folder, but you tried to mount whole zeppelin folder and on start container could not find zeppelin files.
Correct mount examples:
docker run \
-p 8080:8080 \
-v /home/user/zeppelin_notebooks:/zeppelin/notebook \
apache/zeppelin:0.8.0
docker run \
-p 8080:8080 \
--mount type=bind,source="$(pwd)"/zeppelin_notebooks,target=/zeppelin/notebook \
--rm --name zeppelin apache/zeppelin:0.8.0
for My apache zeppelin docker hosted on window 10, the pwd is /opt/zeppelin, the default path for notebooks is /opt/zeppelin/notebook, so I mount my window path as below, Therefore, All notebooks are being save in "C:/Zeppelin/notebook"
docker run -p 8080:8080 -v C:/Zeppelin/Data/:/opt/zeppelin/Data/ -v C:/Zeppelin/notebook:/opt/zeppelin/notebook --name zeppelin apache/zeppelin:0.10.0

Resources