Search code examples
dockerdocker-volumedocker-run

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.

Solution

  • 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