invalid argument for "--mount" flag: unexpected key 'addr' - docker

I want to use docker nfs volume.
What I have tried:
1. Create a volume first then use it, it's OK
docker volume create --driver local --opt type=nfs --opt o=nfsvers=4,addr=10.192.244.109 --opt device=:/var/lib/lava/dispatcher/tmp my1
docker run -it --rm --name nfs-test -v my1:/data alpine sh
2. Directly use volume when docker run, it's also OK
docker run -it --rm --name nfs-test --mount type=volume,volume-driver=local,dst=/data,volume-opt=type=nfs,volume-opt=device=:/var/lib/lava/dispatcher/tmp,"volume-opt=o=addr=10.192.244.109" alpine sh
The problem happens when I want to specify nfsvers=4 in docker run:
# docker run -it --rm --name nfs-test --mount type=volume,volume-driver=local,dst=/data,volume-opt=type=nfs,volume-opt=device=:/var/lib/lava/dispatcher/tmp,"volume-opt=o=nfsvers=4,addr=10.192.244.109" alpine sh
invalid argument "type=volume,volume-driver=local,dst=/data,volume-opt=type=nfs,volume-opt=device=:/var/lib/lava/dispatcher/tmp,volume-opt=o=nfsvers=4,addr=10.192.244.109" for "--mount" flag: unexpected key 'addr' in 'addr=10.192.244.109'
See 'docker run --help'.
You could see Item1 shows we could specify nfs version when use nfs volume, while Item2 shows we could directly use nfs volume within docker run without pre-create a volume.
But, how I could specify nfs version when directly use docker run? What's the correct format here?

This works for me:
--mount 'type=volume,dst=/data,volume-driver=local,volume-opt=type=nfs,volume-opt=device=:/var/lib/lava/dispatcher/tmp,"volume-opt=o=addr=10.192.244.109,rw,nfsvers=4"'
Seems like the argument parser is picky with the quotes.
It is parsed as an extra argument then.
Alternately you can use
..,volume-opt=o=nfsvers=4,volume-opt=o=addr=10.192.244.109

Related

Docker mount CIFS in run command

I want to mount a CIFS share for my docker container to use. This already worked by explicitly creating a docker volume like so:
docker volume create --driver local --opt type=cifs --opt o=vers=2.0,username=xxxx,password=xxxx --opt device=//servername/Documents Documents
docker run -i --rm -v Documents:/mnt busybox ls -l /mnt
however I want to prevent that I have to create explicit volumes. As it has worked similarly for NFS volumes I now want to mount the volume in the docker run command directly:
docker run -i --rm --mount type=volume,volume-driver=local,dst=/mnt,volume-opt=type=cifs,volume-opt=o=vers=2.0,volume-opt=o=username=xxxx,volume-opt=device=//servername/Documents busybox ls -l /mnt
Here I am getting 'permission denied' errors, which is obvious as I have not used the password. How can I specify the password? All my attempts writing something produced different error messages.
docker run -i --rm --mount type=volume,volume-driver=local,dst=/mnt,volume-opt=type=cifs,volume-opt=o=vers=2.0,volume-opt=o=username=xxxx,password=xxxx,volume-opt=device=//servername/Documents busybox ls -l /mnt
gives me unexpected key 'password' in 'password=xxxx'
docker run -i --rm --mount type=volume,volume-driver=local,dst=/mnt,volume-opt=type=cifs,volume-opt=o=vers=2.0,volume-opt=o=username=xxxx,volume-opt=o=password=xxxx,volume-opt=device=//servername/Documents busybox ls -l /mnt
gives me password=xxxx: invalid argument.
My feeling is I need to somehow escape the comma but do not know how.

Docker volume not showing running linux container on Windows 10

I am running Docker for Windows v19.03.12. I am running a linux container from Windows 10. I am sharing my entire c:\ drive with Docker (see image). I am trying to testing a container locally and need to pass a credentials file to the container.
When I run the following command:
docker run --rm -p 9215:80 -p 44371:443 --name test -t createshipment:latest -v c:/temp:/data
When I explore the container I do not see a /data folder at all (see image).
I am not sure what else to try to share a folder when testing docker locally.
The command docker run expects the image name as the last argument, before any arguments to the image's entrypoint. In the OP's post, the image name precedes the -v ... argument, so -v ... is actually passed to the image's entrypoint.
docker run --rm -p 9215:80 -p 44371:443 --name test -t \
-v c:/temp:/data createshipment:latest
For the sake of completeness, here are the relevant excerpts from the documentation for the command-line options used here:
Usage: docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
...
--name string Assign a name to the container
-p, --publish list Publish a container's port(s) to the host
--rm Automatically remove the container when it exits
-t, --tty Allocate a pseudo-TTY
-v, --volume list Bind mount a volume

How to get inside docker container to see the mounted volume?

I am trying to buld a simple docker file that has a debian image.
Also, I want to mount my local volume inside the docker container.
The problem I have is that how do I get inside the container to see the volume mounted.
$docker run -d -it bash --mount type=bind,source="$(pwd)",target=/app docker_test:latest
43db16a76d50f1da0f8589c9ec460080ccef40122c9bc54abad3230dbbfe7885
I believe this 43db16a.. is container id. Even I try to attach to this container id I get an an error message. It says you cannot attach to the stop container. What am I missing here.
It works if I do
docker run -d -it --name test_docker1 --mount type=bind,source="$(pwd)"/,target=/app docker_test:latest
and then
docker attach
d6bd3cc6dc667e742d0bb3c7fbec58935046c1bf7a2e0b6806d48817082c05be
Also, it works when I do
$docker run --rm -ti --mount type=bind,source="$(pwd)"/,target=/app docker_test:latest
In another terminal do a docker ps, then look for the image you are looking for and copy the id, then do a docker exec -ti <your-image> bash there you have a bash terminal inside the container and you can check the mounted volume.

docker volume during docker run

I am trying to mount library present in the container into docker volume during docker run . The command is as below:
docker run -d --name mbus-docker -it --rm --mount source=/mbus/lib/libMurata.a,target=/mbus_volume mbus-docker
I have verified by execing into the container that the library is present in path /mbus/lib/libMurata.a
When I try to mount the library on to volume.
I am getting the below error:
docker: Error response from daemon: create /mbus/lib: "/mbus/lib" 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.
If you want to mount /mbus/lib/libMurata.a onto /mbus_volume path inside container then specify the type for mount as bind.
Your docker run command should be
docker run -d --name mbus-docker -it --rm --mount type=bind,source=/mbus/lib/libMurata.a,target=/mbus_volume/ mbus-docker
This will mount /mbus/lib/libMurata.a onto /mbus_volume/ folder.
The error you got "/mbus/lib" includes invalid characters for a local volume name says /mbus/lib is invalid volume name. Because the default bind type for mount option is type volume. In this case it will try to create a volume locally on your system with the name /mbus/lib which is an invalid volume name.
Please go through this.
Hope this helps.
Update:
If volume named mbus_volume exists on your host. Then try this:
docker run -d --name mbus-docker -it --rm --mount type=volume,source=mbus_volume,target=/mbus/lib/ mbus-docker
you can just use:
docker run -d --name mbus-docker -it --rm -v /mbus/lib/libMurata.a:/mbus_volume/libMurata.a mbus-docker

Why doesn't the docker volume in Windows Server show up when I run this command?

I have a folder setup on the host machine at c:\testvol.
The docker image does not have a folder at c:\testvol.
When I run:
docker run --rm -d --name {name} {imagename} --v c:\testvol:c:\testvol
Why doesn't the volume show up on the container?
It appears in the docker command you need to specify the image name as the last parameter unless you want to pass arguments to be processed by the docker file.
Also, --v should be -v or --volume as --v is not recognized by the docker command.
The command you want is:
docker run --rm -d --name {name} --volume c:\testvol:c:\testvol {imagename}

Resources