Using docker-machine on Windows with Hyper-V

If you have Docker for Windows installed on your Windows laptop, then you also have Hyper-V enabled. In this case, you can't use Docker Toolbox since it uses VirtualBox, and Hyper-V and VirtualBox cannot coexist and run at the same time. In this case, you can use docker-machine with the Hyper-V driver.

Open a PowerShell console as an administrator. Install docker-machine using Chocolatey as follows:

PS> choco install -y docker-machine

Create a VM called boot2docker in Hyper-V with the following command:

PS> docker-machine create --driver hyperv --hyperv-virtual-switch "My Internal Switch" boot2docker

Note, you must run the preceding command in administrator mode or it will fail.

You should see the following output generated by the preceding command:

Running pre-create checks...
(boot2docker) Image cache directory does not exist, creating it at C:\Users\Docker\.docker\machine\cache...
(boot2docker) No default Boot2Docker ISO found locally, downloading the latest release...
(boot2docker) Latest release for github.com/boot2docker/boot2docker is v18.01.0-ce
....
....
Checking connection to Docker...
Docker is up and running!
To see how to connect your Docker Client to the Docker Engine running on this virtual machine, run: C:\Program Files\Doc
ker\Docker\Resources\bin\docker-machine.exe env boot2docker

To see how to connect your Docker client to the Docker Engine running on this virtual machine, run the following:

C:\Program Files\Docker\Docker\Resources\bin\docker-machine.exe env boot2docker

Listing all VMs generated by docker-machine gives us the following output:

PS C:\WINDOWS\system32> docker-machine ls
NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS
boot2docker - hyperv Running tcp://[...]:2376 v18.01.0-ce

Now, let's SSH into our boot2docker VM:

PS> docker-machine ssh boot2docker

You should be greeted by the welcome screen.

We can test the VM by executing our docker version command, which is shown as follows:

Version of the Docker client (CLI) and server

This is definitely a Linux VM, as we can see on the OS/Arch entry, and has Docker 18.03.0-ce-rc4 installed.