Docker: mount path must be absolute when using volume - docker

I am on a windows host and using git bash.
My goal is to create an alias for Jekyll on my git bash: run the docker image instead of installing all the dependencies. I also want to store the "gems" in a local docker volume.
I would like to use the image jekyll/jekyll:stable and the image has a readme here.
This is the alias that I have in my aliases.sh:
alias jekyll='winpty docker run --rm --volume=$PWD:/srv/jekyll --mount type=volume,src=gems,dst=/usr/gem,volume-driver=local -it jekyll/jekyll:stable'
Issuing jekyll results in:
docker: Error response from daemon: invalid mount config for type "volume": invalid mount path: 'C:/Program Files/Git/usr/gem' mount path must be absolute. See 'docker run --help'.
I don't understand: I am trying to mount a volume, not a bind mount. I have also tried to use the more simplistic "-v" syntax, same result. Is my docker trying to mount gems as a (directory) bind mount?
I also tried to debug this with bash set -x, the actual command issued was winpty docker run --rm --volume=/h/:/srv/jekyll --mount type=volume,src=gems,dst=/usr/gem,volume-driver=local -it jekyll/jekyll:stable which looks OK.
UPDATE: It seems that perhaps the /usr destination (in container) is being translated as C:/Program Files/Git/usr/gem which is wrong... I'd need to somehow insert a literal /usr/ in my command.

Related

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

Trying to run "comitted" Docker image, get "cannot mount volume over existing file, file exists"

I am developing a Docker image. I started with a base image and was working inside it interactively, using bash. I installed a bunch of stuff, and the install (which included compiling a lot of code) took over 20 minutes, so to save my work, I used:
$ docker commit 0f08ac958391 myproject:wip
Now when I try to run the image:
$ docker run --rm -it myproject:wip
docker: Error response from daemon: cannot mount volume over existing file, file exists /var/lib/docker/overlay2/95aa9a9ea7cc0b1ba302adbd287e4d7059ee4fbe64183404df3bc65df332ee63/merged/run/host-services/ssh-auth.sock.
What is going on? How do I fix this?
Note about related/duplicate questions: while there are other questions about this error message, none of the answers directly explain why the error happens in this situation or what to do about it. In fact, most of the questions have no answers at all.
When I ran the base image, I included a mount for the SSH agent socket:
$ docker run --rm -it -v /run/host-services/ssh-auth.sock:/run/host-services/ssh-auth.sock myproject:dev /bin/bash
This bind mounts a file from the host (actually the Docker daemon VM) to a file in the Docker container. When I committed the running image, the image contained the file /run/host-services/ssh-auth.sock. The image also contained an empty volume reference to /run/host-services/ssh-auth.sock. This means that when I ran
$ docker run --rm -it myproject:wip
It was equivalent to running
$ docker run -v /run/host-services/ssh-auth.sock --rm -it myproject:wip
Unfortunately, what that command does is create an anonymous volume and mount it into the directory /run/host-services/ssh-auth.sock in the container. This works if the container has such a directory or even if it does not. What causes it to fail is if the target name is taken up by a file. Docker will not mount a volume over a file.
The solution is to explicitly provide a mapping from a host file to the target volume. Any host file will do, but in my case it is best to use the original. So this works:
docker run --rm -it -v /run/host-services/ssh-auth.sock:/run/host-services/ssh-auth.sock myproject:wip

Windows docker, specifying named volume under winpty command line causing includes invalid characters problem

I want to run docker in Git Bash under Windows.
If use docker run --rm -ti -v my-vol:/myvol my_volume_test:latest under Cmd/Powershell, all is good.
But to use docker under Git Bash, I need to prefix the command with winpty, that's where the problem comes in:
$ winpty docker run --rm -ti -v my-vol:/myvol my_volume_test:latest
C:/Program Files/Docker/Docker/resources/bin/docker.exe: Error response from daemon: create my-vol;C: "my-vol;C"
includes invalid characters for a local volume name, only "[a-zA-Z0-9][a-zA-Z0-9_.-]" are allowed. If you intended
to pass a host directory, use absolute path.
See 'C:/Program Files/Docker/Docker/resources/bin/docker.exe run --help'.
I tried to escape the ':' character, but that didn't work either:
$ winpty docker run --rm -ti -v my-vol\:/myvol my_volume_test:latest
C:/Program Files/Docker/Docker/resources/bin/docker.exe: Error response from daemon: create my-vol;C: "my-vol;C" i
ncludes invalid characters for a local volume name, only "[a-zA-Z0-9][a-zA-Z0-9_.-]" are allowed. If you intended
to pass a host directory, use absolute path.
See 'C:/Program Files/Docker/Docker/resources/bin/docker.exe run --help'.

Volume path or Mount in Windows container

Description
I got error "Error response from daemon: invalid mount config for type "volume": invalid mount path" in Windows Container
Steps to reproduce the issue:
1. DockerFile
FROM microsoft/aspnetcore-build AS base
WORKDIR /app
ENTRYPOINT [ "dotnet", "Test.dll" ]
Run command docker build -t docker-vol .
Run Command docker run -it -p 8001:80 -v D:\Projects\Docker\publish:c:/app --name docker-vol-test docker-vol (This works)
Run Command docker run -it -p 8001:80 --mount "source=D:\Projects\Docker\publish,target=c:/app" --name docker-vol-test docker-vol This fails with Error response from daemon: invalid mount config for type "volume": invalid volume name
I am wondering how to work with --mount and whether it is possible to use relative path instead of absolute path with -v?
You are using a bind mount, but because you have not specified a type, then it has defaulted to volume. In this case, source must be the name of the volume, or omitted for an anonymous volume.
Because you have give a path instead, you are getting this error. If you add a type key to your command, it should work:
docker run -it -p 8001:80 --mount 'type=bind, source="D:\Projects\Docker\publish", target="c:/app"' --name docker-vol-test docker-vol
In answer to your second point, bind mounts require an absolute path. The usual way to use a relative path in Linux-land is to prepend the path with $PWD. In Windows, the equivalent of SPWD would be %cd%, so if you were running from D:\Projects\Docker, then the above would probably be:
docker run -it -p 8001:80 --mount 'type=bind, source="%cwd%\publish", target="c:/app"' --name docker-vol-test docker-vol
Note that I have no experience of Docker under Windows, but I believe the above should work.
The above is correct but if you want to use -v instead the syntax is: docker run -v C:\SomePath:C:\app\somePath image
Note the path must exist or the command fails.

Cannot mount volume in docker container when directory name contains colon

I cannot mount a volume to a docker container when the directory name contains a colon (:)
The name of the directory is 2012-08-05-00:16:37 and I prefer not renaming the directory. I tried:
docker run -it --name test1 \
-v /host_system_path/2012-08-05-00\:16\:37/:/container_path/2012-08-05-00\:16\:37/
image_name
I get the error:
docker: Error response from daemon: invalid bind mount spec.See
'docker run --help'.
If I rename the directory without spaces or only with hyphens, then the directory is mounted into the container without any issues. Can someone point out how can I solve the problem when the directory contains a colon.
I am on Ubuntu:16.04 and Docker version 17.06.0-ce.
Colons are currently not supported when specifying directory mappings via -v, and it seems you cannot escape them either.
You need to leverage --mount instead:
docker run ... --mount type=bind,source=/some:colon:file,destination=/container-path ...
In the worst of cases, you may of course alternatively still work around this limitation with a temporary system link (ln -s) or rename the target directory temporarily.
It's an open issue with Docker. But in your case, why would docker run -it --name test1 -v /host_system_path:/container_path image_name not be sufficient?

Resources