solo-io / unik

The Unikernel & MicroVM Compilation and Deployment Platform
Apache License 2.0
2.72k stars 191 forks source link

Docker mount path needs to be translated for Docker Toolbox on Windows #167

Closed hsluoyz closed 6 years ago

hsluoyz commented 6 years ago

As Hyper-V and VirtualBox conflict with each other (https://github.com/solo-io/unik/issues/166), I have to use Docker Toolbox instead of Docker for Windows in order to use the VirtualBox provider.

But Docker Toolbox doesn't support Windows-style path when mounting a volume to the container. See details in: https://github.com/docker/toolbox/issues/777. For Unik's case, the unik daemon command fails as follows:

C:\Users\luo>unik daemon --debug
time="2018-06-25T00:16:30+08:00" level=info msg="daemon started" config={{[] [] [] [{my-vbox VirtualBox Host-Only Ethernet Adapter host_only}] [] [] [] [] []} 0.0.0}
time="2018-06-25T00:16:30+08:00" level=info msg="using container versions" versions=map[boot-creator:d0665c8793b16c51 compilers-rump-c-hw:1954dce79e407724 qemu-util:6f5922561bbb86e3 compilers-osv-java:14f2183e5cb49482 compilers-osv-dynamic:59ba07ca2f12ecaa compilers-mirage-ocaml-ukvm:2c35c23771682e9a compilers-rump-base-xen:f841298dae4340f7 compilers-rump-nodejs-hw-no-stub:baebfe68f3283190 compilers-rump-c-xen:65c2c7316ad6fc77 compilers-mirage-ocaml-xen:0cd46f5253c6ca8a compilers-includeos-cpp-hw:694e22e023dbbbc8 compilers-rump-python3-hw-no-stub:81a494acc94d7827 compilers-rump-python3-xen:1496a60a071e79e1 compilers-rump-base-hw:8cd85d4a7ee1009b compilers-rump-go-hw:d1bfbc13602e306d compilers-rump-python3-hw:22bc5378af6e099d compilers-includeos-cpp-common:8de1311f7b1365d9 compilers-rump-base-common:2eb72d1b386ce2a4 compilers-rump-nodejs-hw:b5029ddcc8731a25 vsphere-client:a9538c7c242acbef image-creator:fa560ac11cecae33 compilers-rump-nodejs-xen:2fbc447253ba19b8 compilers-rump-java-hw:e8c77dc577b288d9 compilers-rump-java-xen:43365940a0dd610c rump-debugger-qemu:0a841d0bf71287e6 compilers-rump-go-xen:fe3335e71ed20510]
time="2018-06-25T00:16:30+08:00" level=info msg="Bootstrapping provider virtualbox with config {my-vbox VirtualBox Host-Only Ethernet Adapter host_only}"
time="2018-06-25T00:16:30+08:00" level=info msg="checking if instance listener is alive..."
time="2018-06-25T00:16:30+08:00" level=info msg="listening for udp heartbeat..."
time="2018-06-25T00:16:30+08:00" level=debug msg="ARE WE LISTENING ON THE SOCKET YET?<nil>"
time="2018-06-25T00:16:30+08:00" level=debug msg="socket was&{{0xc04209edc0}}err was<nil>"
time="2018-06-25T00:16:30+08:00" level=info msg="UDP Server listening on 0.0.0.0:9967"
time="2018-06-25T00:16:40+08:00" level=info msg="cannot contact instance listener... cleaning up previous if it exists.."
time="2018-06-25T00:16:41+08:00" level=debug msg="running VBoxManage command" command=[VBoxManage controlvm VboxUnikInstanceListener poweroff]
time="2018-06-25T00:16:41+08:00" level=debug msg="running VBoxManage command" command=[VBoxManage unregistervm VboxUnikInstanceListener --delete]
time="2018-06-25T00:16:41+08:00" level=info msg="compiling new instance listener"
time="2018-06-25T00:16:41+08:00" level=info msg="Build cmd for container projectunik/compilers-rump-go-hw:d1bfbc13602e306d" args=[run --rm -e ROOT_PATH=github.com/solo-io/unik/instance-listener -e BOOTSTRAP_TYPE=nostub -v C:\Users\luo\AppData\Local\Temp\vbox.instancelistener.110230039:/opt/code --name=d414ced0-169a-46c5-9ed2-9c40bd8bc0d5 projectunik/compilers-rump-go-hw:d1bfbc13602e306d]
time="2018-06-25T00:16:41+08:00" level=debug msg="running command" command=[docker run --rm -e ROOT_PATH=github.com/solo-io/unik/instance-listener -e BOOTSTRAP_TYPE=nostub -v C:\Users\luo\AppData\Local\Temp\vbox.instancelistener.110230039:/opt/code --name=d414ced0-169a-46c5-9ed2-9c40bd8bc0d5 projectunik/compilers-rump-go-hw:d1bfbc13602e306d]
time="2018-06-25T00:16:42+08:00" level=debug msg="docker: Error response from daemon: invalid mode: /opt/code."
time="2018-06-25T00:16:42+08:00" level=debug msg="See 'docker run --help'."
time="2018-06-25T00:16:42+08:00" level=error msg="running daemon failed: [cmd/daemon.go:86] daemon failed to initialize: {[daemon/daemon.go:107] initializing virtualbox provider: {[virtualbox/virtualbox_provider.go:49] deploying virtualbox instance listener: {[virtualbox/deploy_instance_listener.go:39] compiling instance listener source to unikernel: {exit status 125}}}}"

C:\Users\luo>

This error is because -v C:\Users\luo\AppData\Local\Temp\vbox.instancelistener.110230039:/opt/code is not recognized by Docker Toolbox. But -v /c/Users/luo/AppData/Local/Temp/vbox.instancelistener.110230039:/opt/code works. I don't think Docker will fix this issue very in a near future, because They already mark Docker Toolbox as deprecated and their Git repo has been inactive for more than half a year. So I prefer a fix at the application side (aka Unik).

My solution is:

  1. First determine which one is running, Docker Toolbox or Docker for Windows. Here's a post that provides a way: https://stackoverflow.com/questions/43242218/how-can-a-script-distinguish-docker-toolbox-and-docker-for-windows
  2. If Docker for Windows is running, then do nothing.
  3. If Docker Toolbox is running, then perform a translation on the mount path of the docker run call, translate paths like C:\xxx to /c/xxx.

Does it sound OK? If it's OK, I will make a PR.