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
Related
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
I have the following docker file
RUN touch /root/testing
VOLUME ["/root"]
after i build and inpect and under config i see
"Volumes": {
"/root": {}
},
after i run /bin/bash and inpect
"Mounts": [
{
"Type": "volume",
"Name": "fc1dc25de37d6d7593a21443cd2bef74a0a6a4e3276b8353199054404665c398",
"Source": "/var/lib/docker/volumes/fc1dc25de37d6d7593a21443cd2bef74a0a6a4e3276b8353199054404665c398/_data",
"Destination": "/root",
"Driver": "local",
"Mode": "",
"RW": true,
"Propagation": ""
}
],
When i start a container it creates a local volume and mount it on /root. It also copies the contents of /root into the local mount
if i do on the host we can see testing file in it
ls /var/lib/docker/volumes/fc1dc25de37d6d7593a21443cd2bef74a0a6a4e3276b8353199054404665c398/_data
testing
But the local volume will be destroyed immediately after the container is killed.
So what is the purpose of local volume. Because sometimes i if by mistake kill the container and still i want to have some data craeted by my container on the local volume, then its not possible since the local volume is also deleted.
I wanted to try named volumes.
I created
docker volume create test
then i my docker file:
RUN touch /root/testing
VOLUME [{"Name":"test","Destination":"/root","external":"true"}]
OR
VOLUME [ "Name:{"Destination":"/root","external":"true"}"]
When i try to build i get:
Error response from daemon: when using JSON array syntax, arrays must be comprised of strings only
Then the only option left out is mount volume from command line rather than Dockerfile
docker run --rm -it --mount source=test,destination=/root archlinux/test /bin/bash
[root#7c7001221c14 /]# ls /root
testing
Now i check the test volume contents:
$ docker run --rm -it --mount source=test,destination=/tmp/myvolume archlinux/base ls /tmp/myvolume
testing
Here since test volume is completely empty so it copied the contents of the /root (i.e file testing) from the image when i do docker run --rm -it --mount source=test,destination=/root archlinux/test /bin/bash into the volume test
But if the test volume is not empty befor i docker run --rm -it --mount source=test,destination=/root archlinux/test /bin/bash: i.e
sudo cd /var/lib/docker/volumes/test/_data
rm -rf *
mkdir hellophp
and then do
docker run --rm -it --mount source=test,destination=/root archlinux/test /bin/bash
[root#7c7001221c14 /]# ls /root
hellophp
So my observations are:
---- VOLUME ["/path/in/container/"] will only create local volumes we cant use named volumes here
---- If i want to use named volumes then
a) create a named volume
docker volume create test
b) mount the named volume into the container path
--mount source=test,destination=/path/in/container
------ *** Most important observation
IF named volume is empty (no files in it) then after runnnig
docker run --rm -it --mount source=test,destination=/path/in/container IMAGENAME CMD
it will copy the contents of /path/in/container to test volume and then mount test volume at /path/in/container
ELSE (i.e named volume has some file in it) then after running
docker run --rm -it --mount source=test,destination=/path/in/container IMAGENAME CMD
It will not change the test volume by copying files from /path/in/container to test volume before mounting.
It will mount test volume at /path/in/container. So any files existing in the /path/in/container will not be available in the container.
If you are running a database in docker you can mount a local directory directly into your container using the -v option on the run command.
docker run -d \
-v <local path>:<container path>:z \
..
..
<your image>
The actual storage will be persistent on your local filesystem, and accessible in the container when the container is running.
Also read this
https://docs.docker.com/storage/volumes/
This question already has answers here:
Locating data volumes in Docker Desktop (Windows)
(17 answers)
Closed 4 years ago.
I am relatively new to docker. I want to use a database with volume to persist. I am in windows 10.
I want to check where the volumns are created in my machine.
When i run the command
C:\Users\satul>docker volume inspect 368984d12c3525d8752d249347cfd563afb46c847e1c109afa9785bf54b89701 [
{
"CreatedAt": "2018-06-25T22:43:29Z",
"Driver": "local",
"Labels": null,
"Mountpoint": "/var/lib/docker/volumes/368984d12c3525d8752d249347cfd563afb46c847e1c109afa9785bf54b89701/_data",
"Name": "368984d12c3525d8752d249347cfd563afb46c847e1c109afa9785bf54b89701",
"Options": null,
"Scope": "local"
} ]
Since this is a windows box, i donot have folder /var/lib/docker/volumes/. Where exactly is the volumn folder in windows so that i can backit up if required.
You should not back up volumes by backing up /var/lib/docker/volumes directory. Instead you should use command (it will create the backup in your current working directory):
docker run --rm --volumes-from container-name -v $(pwd):/backup ubuntu tar cvf /backup/backup_name.tar /mount/point/inside/container
Eg. for Docker registry the command looks like this:
docker run --rm --volumes-from registry -v $(pwd):/backup ubuntu tar cvf /backup/registry_backup.tar /var/lib/registry
And to restore the backup you should use command:
docker run --rm --volumes-from container-name -v $(pwd):/backup ubuntu bash -c "cd /mount/point/inside/container && tar xvf /backup/registry_backup.tar --strip number_of_leading_directory_components_in_mount_point_path"
Eg. to restore backup of Docker registry:
docker run --rm --volumes-from registry -v $(pwd):/backup ubuntu bash -c "cd /var/lib/registry && tar xvf /backup/registry_backup.tar --strip 3"
Usually /var/lib/docker is mounted on C:\Users\Public\Documents\Hyper-V\Virtual hard disks. You can check it out by looking at your docker settings.
A docker volume is just a directory on your host machine with all your container data, so you could use any methods you wish to backup your data.You can see more about docker volumes in official documentation
See also
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 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.