Docker Desktop and Hyper-V.
My aim was to run docker destkop on my host machine and accessing that docker instance from the Hyper-V machine that i have running on the same host machine. Here are the steps i followed. On Windows 10 Pro
On the host
Docker
Add the network connection
- Search on the menu for "View network connections" and check what are the existing interfaces
- Add a new network interface on Hyper-V Manager (Virtual Switch Manager->New Virtual Network Switch) and select "Internal" as "Connection Type". Leave everything as default, name it e.g. "Internal network"
- Always on the manager open the guest vm "Settings" and "Add a new Hardware" selecting "Network Adapter"
- Select the "Internal network" virtual switch and leave it as is
Setup the network configuration
- Search on the menu for "View network connections" and right click on the one just added to open the properties
- Open the "Internet protocol Version 4 (TCP/IPv4)" and set the following (this is a likely unused address). This will be the static address of your host machine inside the "Internal network"
- Check "Use the following IP Address"
- IP Address: 192.168.4.1
- Netmask: 255.255.255.0
Install the proxy for docker
- Start "Docker Desktop" and open the settings (the wheel on left top)
- In "General" check the "Expose daemon on blah..blah 2375"
- Apply and restart
Open a command line as adminstrator and run the following. This will install a proxy for docker, exposed on all addresses
docker run -d --restart=always -p 23750:2375 -v /var/run/docker.sock:/var/run/docker.sock alpine/socat tcp-listen:2375,fork,reuseaddr unix-connect:/var/run/docker.sock
On the guest machine
- Start the virtual machine (actually for me was a Windows 10 "unregistered" instance)
Setup the network
- Search on the menu for "View network connections" and right click on the one just added to open the properties. Will be the one without internet connection
- Open the "Internet protocol Version 4 (TCP/IPv4)" and set the following (this is a likely unused address). This will be the static address of your guest machine inside the "Internal network"
- Check "Use the following IP Address"
- IP Address: 192.168.4.2
- Netmask: 255.255.255.0
Install Python
- Download and install Python https://www.python.org/downloads/
- Search for "Edit the system environment variables" and add the python's path if not present double clicking on the "PATH" variable, adding the following
- C:\Users[YourUserName\AppData\Local\Programs\Python\Python[PythonVersion]
- C:\Users[YourUserName\AppData\Local\Programs\Python\Python[PythonVersion]\Scripts
- Add a new variable DOCKER_HOST containing "tcp://192.168.4.1:23750"
Open a command line and check if ptyhon is installed running
python
Check if pip is installed running
pip -V
If it is not, download get-pip.py to a folder on your computer.
- Open a command prompt and navigate to the folder containing the get-pip.py installer.
Run the following command and check again
python get-pip.py
Install Docker
Then run
pip install docker docker-compose
Should then download the docker executable from https://github.com/StefanScherer/docker-cli-builder/releases/ inside the C:\Users[YourUserName\AppData\Local\Programs\Python\Python[PythonVersion]\Scripts directory
Now you can verify the installation running
docker ps
If you like you can install the lovely Portainer, a really nice control panel for docker:
docker run -d -p 3040:9000 --name portainer --restart=always -v portainer_data:/data portainer/portainer
Last modified on: February 08, 2021