0

Say I have a virtual box virtual machine provisioned through Vagrant. I then provision it with docker-machine - so far all good: I can docker-machine ssh into the box and list it ok with docker-machine ls.

In the past, when not yet using dokcer-machine, my usual workflow would involve sshing into the virtual box, installing docker and spinning up my containers.

As far as I understand this is not longer needed as I can control docker containers within the virtual box through docker-machine (and docker itself) from outside the virtual box (essentially from my win dev machine).

Question: how can I mount directories from inside the vm into the container when I am running the docker command from outside the container?

Example to further clarify:

1) old approach. ssh into vbox and run

docker run -i -t --net=try-net \
--name XXXX \
-v ${PWD}/xxxx/yyyy.py:/zzzzz/xxxx/yyyy.py \
-d me/image

2) docker-machine approach. I switch the docker-machine env onto the box. Now how do I reference a folder in the vbox from outside the box? Is this even possible?

From my win host in a Linux like shell:

docker run -v /c/x/y/z:/home --name postgres3 -d postgres:9.5

gets me:

c:\Program Files\Docker\Docker\Resources\bin\docker.exe: Error response from daemon: Invalid bind mount spec "c:\x\y\z\;C:\Program Files (x86)\Git\home": invalid mode: \Program Files (x86)\Git\home.

Riziero
  • 144
  • 2
  • 14
  • That volume parameter `c:\x\y\z\;C:\Program Files (x86)\Git\home` isn't at all what you input. It looks like the shell munged the path to make it look like the windows path, and then changed the colon to a semicolon. Have you tried quoting it with single quotes or using another shell? – BMitch Jan 16 '17 at 14:24
  • Been using gitbash and got that. With Canonical on windows I came across this nug https://github.com/docker/machine/issues/3719 -.- – Riziero Jan 16 '17 at 17:35

1 Answers1

1

If you spin up containers using a docker-toolbox install, the VM's are pre-configured to share the /Users folder from the host into the VM which can then be used by containers.

Since you're doing this manually with your own Vagrant install, you'll need to share the folders yourself. This question should walk you through the steps to share a folder from the parent OS into the VM which can be used by Docker containers you spin up with docker-machine.


Edit: with the parent OS synced the the VM, any containers you run inside the VM will just mount volumes there. Docker-machine isn't really a factor, it's just pointing the docker CLI to the selected docker host. The docker CLI would look like:

docker run -v /path/on/vm:/path/in/container image
Community
  • 1
  • 1
BMitch
  • 231,797
  • 42
  • 475
  • 450
  • sadly that answer only describes how to sync folders from the host into the vagrant box (which I am already doing). I am trying to sync those folders from the Vagrant box into the docker container, all of which needs to happen from my host through docker-machine. – Riziero Jan 15 '17 at 22:20
  • My apologies, didn't realize that's where your question was. Once the files are synced to the VM, you can mount them inside the container by using the VM path. See my edit above. – BMitch Jan 15 '17 at 23:29
  • Ok we are getting closer :) That's what I had in mind but when I provision I only seem to be getting the engine inside the Vagrant box. As in, I cant run docker from inside it, but I can run docker from my local host after switching the env to the box itself with docker-machine. I.e.: `docker-machine.exe env vbox` `docker run --net=my-net --name postgres -d postgres:9.5` effectivelly spins up the container in vbox from my host. Ideally I'd need a way to mount vbox's folders into the container from the docker command above (which again runs on my box) – Riziero Jan 16 '17 at 09:53
  • Unless the docker run command you posted in the answer is really meant to be run from my host and /path/on/vm is actually a folder in the Vagrant box ? – Riziero Jan 16 '17 at 10:04
  • The latter, not really following how else you're attempting to run it. – BMitch Jan 16 '17 at 10:53
  • I've edited the question to provide more details. Hope it's more clear now. – Riziero Jan 16 '17 at 11:11