Docker volume mount fails with the below error - docker

Docker volume mount fails with the below error.
I'm trying to run a container with a config file in the volume and it fails with the below errors.
root#ip-172-31-21-249:~/data# docker run -it -p 8080:8080 -p 29418:29418 -v /root/data:/var/gerrit/etc/ forkub
error: could not lock config file /var/gerrit/etc/gerrit.config: Permission denied
root#ip-172-31-21-249:~/data# docker run -it -p 8080:8080 -p 29418:29418 -v /root/data:/var/gerrit/etc forkub
error: could not lock config file /var/gerrit/etc/gerrit.config: Permission denied
root#ip-172-31-21-249:~/data# docker run -it -p 8080:8080 -p 29418:29418 -v /root/data/:/var/gerrit/etc forkub
error: could not lock config file /var/gerrit/etc/gerrit.config: Permission denied
root#ip-172-31-21-249:~/data# docker run -it -p 8080:8080 -p 29418:29418 -v /root/data/:/var/gerrit/etc/ forkub
error: could not lock config file /var/gerrit/etc/gerrit.config: Permission denied
root#ip-172-31-21-249:~/data# docker run -it -p 8080:8080 -p 29418:29418 -v /root/data/:/var/gerrit/etc/gerrit.config forkub
docker: Error response from daemon: OCI runtime create failed: container_linux.go:349: starting container process caused "process_linux.go:449: container init caused \"rootfs_linux.go:58: mounting \\\"/root/data\\\" to rootfs \\\"/var/lib/docker/overlay2/0a5356aed5a1aa1d1359912ccba7547db55b0377b3a509b898828734868e335a/merged\\\" at \\\"/var/lib/docker/overlay2/0a5356aed5a1aa1d1359912ccba7547db55b0377b3a509b898828734868e335a/merged/var/gerrit/etc/gerrit.config\\\" caused \\\"not a directory\\\"\"": unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type.
ERRO[0000] error waiting for container: context canceled
Any suggestions on fixing this is really appreciated.
Thank you,
Anish

Probably the process in the container does not run as root but as some other user. The file belongs to root though and is not readable by the user that runs the process. So the process can not read the file.
So you need to make sure that the user that runs the process in the container can access those files. The easiest way would be to make /root/data world read-/writeable (chmod -R 777 /root/data) but this is obviously not the best way. The right way to do this, would be to find out which user is running the process in the container and change the ownership of /root/data and everything in it to that user.
The problem with docker run -it -p 8080:8080 -p 29418:29418 -v /root/data/:/var/gerrit/etc/gerrit.config forkub is, that you are trying to mount a directory /root/data to a file. This does not work.

Related

Is it possible to access mptcp sysctl inside docker?

I would like to access sysctl -n net.mptcp.mptcp_enabled from docker container, but currently I couldn't achieve it. I already tried the below things.
1.
docker run -d --sysctl net.mptcp.mptcp_enabled=1 --name=test -p 3100:3100 my_container
75dcbdc65a1539ce734a413cb6e23bf216aea76f6533c52280d3e866270424b9
docker: Error response from daemon: failed to create shim: OCI runtime create failed: container_linux.go:380: starting container process caused: process_linux.go:545: container init caused: write sysctl key net.mptcp.mptcp_enabled: open /proc/sys/net/mptcp/mptcp_enabled: no such file or directory: unknown.
docker run -d --cap-add=SYS_ADMIN --privileged --name=test -p 3100:3100 my_container
This time container starts but there is no file under /proc/sys/net/mptcp/mptcp_enabled
3.
docker run -d -v /proc:/proc --cap-add=SYS_ADMIN --privileged --name=test -p 3100:3100 my_container
This is also the same as 2.
I saw that a sysctl that starts with net.* are namespaced but wonder why this is not working.
Note: My host machine has mptcp supported kernel and I can see all mptcp related files under /proc/sys/net/mptcp/*
I faced the same issue. Using --net=host should solve it.
Try this:
docker run -d --net=host --name=test -p 3100:3100 my_container

How to mount an Arvados FUSE to a Docker container as volume

I would like to add a file system view of Arvados Keep to a Docker container. I created this file system view with arv-mount and it is based on File System in Userspace (FUSE).
Approach 1
$ docker run --rm -it -v /home/test/arv:/opt ubuntu:hirsute bash
docker: Error response from daemon: error while creating mount source path '/home/test/arv': mkdir /home/test/arv: file exists.
Approach 2
I also tried bind mounts
$ docker run --rm -it --mount type=bind,source=/home/test/arv,target=/opt,bind-propagation=rshared ubuntu:hirsute bash
docker: Error response from daemon: invalid mount config for type "bind": stat /home/test/arv: permission denied.
Both approaches I tried as non-root user (I configured Docker for non-root users) and root user.
I made it working by
Adding user_allow_other to /etc/fuse.conf
Creating FUSE mount with arv-mount --allow-other /home/test/arv

Pass configuration file to mosquitto in Docker container

Trying to run masquitto Docker container on Windows. I have directory structure:
..
mosquitto
config
-- mosquitto.conf
data
log
I run command:
docker run -it -p 1883:1883 -p 9001:9001 -v mosquitto.conf:/mosquitto/config/mosquitto.conf -v /mosquitto/data -v /mosquitto/log eclipse-mosquitto
Got error:
docker: Error response from daemon: source /var/lib/docker/overlay2/c54f317f73085489398e1b2c4ffbc85fbdb18073e8a0fa60f11a7f7222fbc49d/merged/mosquitto/config/mosquitto.conf is not directory.
See 'docker run --help'.
What I do wrong?
UPD
I tried to provide full path to config file on host machine:
docker run -it -p 1883:1883 -p 9001:9001 -v C:/docker_tst/eclipse-mosquitto/mosquitto.conf:/mosquitto/config/mosquitto.conf eclipse-mosquitto
Got error:
docker: Error response from daemon: OCI runtime create failed: container_linux.go:370: starting container process caused: process_linux.go:459: container init caused: rootfs_linux.go:59: mounting "/run/desktop/mnt/host/c/docker_tst/eclipse-mosquitto/mosquitto.conf" to rootfs at "/var/lib/docker/overlay2/d9a7cbcb0f85b195dc5ee2d0999b3df8c84324552f6c45cf218876e9b96ed826/merged/mosquitto/config/mosquitto.conf" caused: not a directory: unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type.
PS C:\docker_tst\eclipse-mosquitto>
From the comments, the solution was to provide an absolute path to the single mounted file, per this answer.
On Unix based systems or in Windows Subsystem for Linux, you can do this by running something like:
docker run -v $PWD/filename:/path/in/container IMAGE_NAME
However, the process is different on Windows, per this answer.
In PowerShell, you can run Get-Location or pwd to get the current directory where your file is and switch the \ to / (forward slashes). For this example, the solution was to use this command:
docker run -it -p 1883:1883 -p 9001:9001 -v C:/docker_tst/eclipse-mosquitto/mosquito/config/mosquito.conf:/mosquitto/config/mosquitto.conf eclipse-mosquitto

How can I add an extra bind-mount to this configuration?

There are two ways of passing arguments, I chose this one:
sudo docker run -d -e url=http://example.com --name myBlog -p 3001:2368 -v "$(pwd)/content":/var/lib/ghost/content ghost:latest
How can I add an extra command line so it also adds a bind-mount to:
$(pwd)/testFolder/config.production.json the file on the volume would be here: :/var/lib/ghost/config.production.json
Also the file on the host doesn't exist yet, once I mount the container, it the container creates it.
This is what I've tried:
sudo docker run -d -e url=http://example.com --name myBlog6 -p 3006:2376 -v "$(pwd)/content6":/var/lib/ghost/content -v /home/ubuntu/config6:/var/lib/ghost/config.production.json ghost:latest
But I'm getting this error:
docker: Error response from daemon: OCI runtime create failed: container_linux.go:349: starting container process caused "process_linux.go:449: container init caused \"rootfs_linux.go:58: mounting \\\"/home/ubuntu/config6\\\" to rootfs \\\"/var/lib/docker/overlay2/f8c4ed9231552e91caaeb4f0b8fb9f02108f838e94b659bf049a2df365cd26ef/merged\\\" at \\\"/var/lib/docker/overlay2/f8c4ed9231552e91caaeb4f0b8fb9f02108f838e94b659bf049a2df365cd26ef/merged/var/lib/ghost/config.production.json\\\" caused \\\"not a directory\\\"\"": unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type.
Thanks
If I got it correctly, you get this error because you are trying to mount directory /home/ubuntu/config6 to a file ...config.production.json.
If you say that file config.production.json will be created and it's content is written in run time after the container is initialized, then you could try to created an empty file
touch /home/ubuntu/config6/config.production.json
sudo chmod 777 /home/ubuntu/config6/config.production.json
and then mount a file to the container
sudo docker run -d \
-e url=http://example.com \
--name myBlog6 -p 3006:2376 \
-v "$(pwd)/content6":/var/lib/ghost/content \
-v /home/ubuntu/config6/config.production.json:/var/lib/ghost/config.production.json \
ghost:latest
And after container will write a content to file, you will be able to see it and load next time to the container.
The chmod command is used to make sure, that you app running inside of the container will have rights to write to this file.

docker nginx Mount -v

docker run command error: (I was knocking on the document command, Docker
version 18.03.0-ce), ask why?
docker run -p 80:80 --name mynginx -v $PWD/www:/www -v $PWD/conf/nginx.conf:/etc/nginx/nginx.conf -v $PWD/logs:/wwwlogs -d nginx
The error is as follows:
ebb97ea2c176cb1693912f54960db6281b30c95482c67df37183a8e1c618ca92
docker: Error response from daemon: OCI runtime create failed: container_linux.go:348: starting container process caused "process_linux.go:402: container init caused \"rootfs_linux.go:58: mounting \\\"/home/xiao/nginx/conf/nginx.conf\\\" to rootfs \\\"/var/lib/docker/overlay2/17a9b49be13458de18ce62753d49a94a3d6dc6685af7483f6e9b2e12d20bb92c/merged\\\" at \\\"/var/lib/docker/overlay2/17a9b49be13458de18ce62753d49a94a3d6dc6685af7483f6e9b2e12d20bb92c/merged/etc/nginx/nginx.conf\\\" caused \\\"not a directory\\\"\"": unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type.
Problem is due to $PWD/conf/nginx.conf exists in your container, and command docker run -p 80:80 --name mynginx -v $PWD/www:/www -v $PWD/conf/nginx.conf:/etc/nginx/nginx.conf ... is trying to replace nginx.conf in your container with nginx.conf from your host.
If you want to have a nginx server in your container with your host's nginx.conf configuration, you have to assure yourself that nginx.conf doesn't exist in container.
If it exists in containers because you're installing it in Dockerfile and you want to keep in container your host nginx.conf file anyway, you need add RUN rm -f $PWD/conf/nginx.conf to your container Dockerfile after nginx installation.
Note that I'm only showing you a possible solution for your proposal, but I cannot recommend you to do it until I know why do you need to use your nginx.conf into the file.

Resources