0

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.
Zaks
  • 668
  • 1
  • 8
  • 30
  • When you say docker volume. That volume should exists. Your questions is not that clear. – mchawre Jul 31 '19 at 07:14
  • Docker volume is already existing on the host created using docker volume create --name mbus_volume – Zaks Jul 31 '19 at 07:16

2 Answers2

1

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
mchawre
  • 10,744
  • 4
  • 35
  • 57
  • @zaks Let me know if it helped. – mchawre Jul 31 '19 at 06:24
  • Thanks for the reply. With the modified command it gives me error as " docker: Error response from daemon: invalid mount config for type "bind": bind source path does not exist: /mbus/lib. See 'docker run --help'." – Zaks Jul 31 '19 at 06:48
  • does that folder `/mbus/lib` exists on host? – mchawre Jul 31 '19 at 06:50
  • It exists inside the container . I am trying to mount container directory into docker volume – Zaks Jul 31 '19 at 06:51
  • Does the docker volume already exists. If so then you need to specify volume name in `source` and type should be `volume` ot you can skip it because default type is `volume`. – mchawre Jul 31 '19 at 06:52
  • @zaks what you mean by docker volume? If you want the lib `/mbus/lib/libMurata.a` inside your docker container to be present on `/mbus_volume` folder on your host then you need `-v /mbus_volume:/mbus/lib` option in your docker run command no need for mount. – mchawre Jul 31 '19 at 07:11
  • I am facing small issue. Trying to run two docker containers mounting to the same volume(mbus_volume) 1) docker run -d --name mbus-docker -it --rm --mount type=bind,source=/mbus/lib/libMurata.a,target=/mbus_volume/ mbus-docker 2) docker run -d --name wakaama-docker -it --rm --mount type=bind,source=/murata/lib/wakama.a,target=/mbus_volume/ wakaama-docker . – Zaks Jul 31 '19 at 08:09
  • After running the first container the library is mounted correctly onto the volume . But when I run the second it doesnt . Should I do anything special to make volume mountable to both containers – Zaks Jul 31 '19 at 08:09
  • Have you checked this https://stackoverflow.com/questions/42854936/can-i-mount-same-volume-to-multiple-docker-containers – mchawre Jul 31 '19 at 09:06
  • Accept the answer, if it helped. So that other can know it. – mchawre Jul 31 '19 at 09:10
1

you can just use:

docker run -d  --name   mbus-docker -it --rm -v /mbus/lib/libMurata.a:/mbus_volume/libMurata.a mbus-docker
LinPy
  • 16,987
  • 4
  • 43
  • 57
  • Thanks for your reply. The command create a new-folder inside container named /mbus_volume and puts libMurata.a inside it . It is not adding library inside docker volume – Zaks Jul 31 '19 at 07:09
  • what do you mean by `not adding library inside docker volume` ? – LinPy Jul 31 '19 at 07:13
  • When I inspect docker volume I cannot see anything added inside that – Zaks Jul 31 '19 at 07:15