Configure an environment to use Docker on Hyper-V Ubuntu virtual machines running on a Windows 10 host
Tags: docker, ubuntu, beginners, tutorial
Published: 2022-12-15 16:55:56

This time I want to talk about something not specific to InterSystems IRIS, but that I think is important if you want to work with Docker and your server at work is a PC or laptop with Windows 10 Pro or Enterprise.

As you likely know, containers technology comes basically from Linux world and, nowadays, is on Linux hosts were it shows maximum potential. Those who use Windows on a normal basis see that both, Microsoft and Docker, have done important efforts during these last years that allow us to run containers based on Linux images on our Windows system in a really easy way... but it's something not supported for production systems and, this is the big problem, is not reliable if we want to keep persistent data outside of containers, in the host system,... mostly due to the big differences between Windows and Linux file systems. In the end, _Docker for Windows _itself uses a small linux virtual machine (_MobiLinux_) to run the containers... it does it transparently for the windows user... and it works perfectly well if, as I said, you don't require that your databases survive longer than the container...

Well,...let's get to the point,... the point is that many times, to avoid issues and simplify, we need a full Linux system and, if our server is based on Windows, the only way of having it is through a virtual machine. At least till WSL2 in Windows is released, but that will be another story and sure it'll take a bit of time to become robust enough.

In this article, I'll tell you, step by step, how to install an environment where you'll be able to work, if you need it, with Docker containers on an Ubuntu system in your Windows server. Let's go...

<!--break-->

<kbd>1. Enable Hyper-V</kbd>

If you don't have it enabled yet, go to add `Windows Features` and enable Hyper-V. You'll need to restart (text images is in Spanish, but that's my current locale. I hope that altogether with instructions will help to "decrypt" it if you don't know the Don Quixote's lingua 😉 ) 


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pml4puiimrzom5y34unh.png)

 

<kbd>2. Create an Ubuntu virtual machine on Hyper-V</kbd>

I don't think there is any easier way of creating a virtual machine (VM). Just open the window of the `Hyper-V Manager`,  and go to option  <span style="color:#000099;"><em>Quick Create...</em></span> (right up in your screen) and create your virtual machine using any of Ubuntu versions already offered (you could download an _iso _file of whatever other Linux and so create the VM with a different distro). In my case, I've chosen the last Ubuntu release available: 19.10. Anyway, everything you'll see here is valid for 18.04. In 15 or 20 minutes, depends on what the image takes to download for you, you'll have your new VM created and ready.

<div style="background:#eeeeee;border:1px solid #cccccc;padding:5px 10px;">
  <span style="color:#ffffff;"><span style="background-color:#c0392b;">Important:</span> </span>Leave the option of <em>Default Switch </em>as it's offered <em>.</em> This will guarantee you have access to internet from both, the host and the virtual machine.
</div>


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6qhcsed3q313dudzjhsf.jpg)

<kbd>3. Create a local subnet</kbd>

One of the problems of using vitual machines that I've found very often has to do with network configuration... sometimes works, others don't, or it works if I'm connected with Wi-fi but not by cable or the opposite, or if I stablish a VPN in the windows host, then I lose internet access in the VM, or communication between the VM (Linux) and the host (Windows) gets broken... in short... it's crazy!  Makes me not to trust in my environment when I use my laptop for development, small and quick demos or for presentations, where most likely access to internet is not as important as being sure that communications between my host and my VM(s) work in a reliable way.

With an ad-hoc local subnet, shared between your Windows host and your virtual machines, you solve it. To let them communicate among each other, you use that subnet and that's it. You just have to assign specific IPs to your host and your VMs and all set.

It's really easy to do it with these steps. Just go to <span style="color:#000099;"><em>Virtual Switch Manager...</em></span>  that you'll find in your  `Hyper-V Manager`:


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ycoa3d6he7kb747zle1w.png)

Once there, go to option _<span style="color:#000099;">New  Virtual Switch</span> __ _(it would be like a new network card for the VM afterwards):


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uyh7u3g0xgld1im04htb.png) 

Be sure you define it as _<span style="color:#000099;">Internal Network </span>_, choose the name we want and leave the other options by default


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rgaany66wfi3h6mf3802.png)

Now, if we go to _`Windows Control Panel --> Network and Sharing Center`_, we'll see that we already have there the switch we just created:


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fdoop0ixf8809pt9hzka.png) 

 

<kbd>4. Configure the local Subnet shared by the host and the Virtual Machines</kbd>

At this point you can finish the configuration of your new local network. To do that, set your cursor over the connection  _Mi Nuevo Conmutador LOCAL_,  click and go to <span style="color:#000099;"><em>Properties</em></span>, and from there to <span style="color:#000099;"><em>IPv4 protocol</em></span> so to assign a fixed IP address:


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1ucwlkurs11durid4e7o.png)  

<div style="background:#eeeeee;border:1px solid #cccccc;padding:5px 10px;">
  <span style="color:#ffffff;"><span style="background-color:#c0392b;">Important:</span></span> The IP that you assign here will be your host (Windows) IP in this local subnet.
</div>

 

<kbd>5. Link and configure your new local network to your virtual machine</kbd>

Now come back to your  `Hyper-V Manager`. If your VM is running, stop it. Once stopped, go to its configuration and add the new internal virtul switch:


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fh6q19q6ngnosw80y1t8.png) 

_(Note.- In the image you can see another switch, the Hyper-V Conmutador INTERNO . It's for another subnet that I have. But it's not necessary for you in this configuration) _

Once you click on Add, you will just have to <u>select the switch that you previously created</u>:


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u0tvk9jwn88ywhbrqyvy.png) 

Well, once this is done, click Apply, Accept, ... and you're ready! You just can start and <u>login again in your virtual machine to finish the configuration of the internal connection</u>. To do that, once the VM starts, clicnk on the network icon (right up) and you'll see that you have 2 networks: _eth0_ y _eth1_. The _eth1_ appears as disconnected... by now:


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9dkmpoozey3iekm04vg3.png) 

Go into the configuration of the Ethernet (eht1) and assign a fixed IP for this local subnet, for example: _155.100.101.1_, and the subnet mask:_ 255.255.255.0_


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/su8mgo4sua9mjx9jvokk.png) 

and that's all. Here you have your virtual machine, identified with IP 155.100.101.1 sharing the same subnet with your host.

<kbd>7. Allow access to Windows 10 from your virtual machine</kbd>

You will likely discover that Windows 10 doesn't allow by default connection from other server and, for your windows system, the VM you've just created is precisely that, an external and potentially dangerous server... so you'll have to <u>add a rule in the Firewall</u> to be able to connect to your host from those virtual machines. How? Very easy, just look for `Windows Defender Firewall` in your `Windows Control Panel`, go to <span style="color:#000099;"><em>Advance Configuration</em></span> and  create a <u>new <em><u>Entry Rule</u></em></u>:


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e9m877pct2tiv9bpqt8d.png) 

You can set one port or one or many range of them... (also you can set the rule for all the ports)...


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ryz48ntgvcybkp7m92pa.png) 

The action we want is _<u>Allow Connection</u>_...


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uhdr77kk3wmms5dyedaz.png) 

For _<u>all network types</u>_...


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n7o5gd93cyrvdnw6mlmq.png) 

Give a name to your rule...


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dw2fm3l0z1xs9s68yhfy.png) 

And **important**, inmediately after that, open again the properties of your newley created rule and <u><em>limit the application scope</em></u>, so to apply only for connections within your local Subnet...


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ezls6fxqjp67qnztun22.png) 

<kbd>8. READY. Install Docker and whatever other application in your new Ubuntu Virtual Machine</kbd>

Once you go through the entire installation process and you have your new VM ready and up-to-date, with internet access, etc.. you can install the apps you want... Docker as a minimum, that was the idea from the beginning, also you can install your VPN client if you need it for connection with your company network, VS Code, Eclipse+Atelier,...

Specifically, to install Docker, within your VM, you can follow the instructions you'll find here: <https://docs.docker.com/install/linux/docker-ce/ubuntu/>

Be sure that your Docker runtime is working, download some test image, etc... and that's it.

With this... _**<span style="font-size:16px;"><span style="font-family:Comic Sans MS,cursive;">¡You're all set!</span></span>**_, now you'll be able to have containers running with no limitations (apart from your hardware capacity) in your Ubuntu VM, to which you'll be able to connect from your Windows 10 host, from a browser or an app and the other way around, from your Ubuntu VM  to your Windows 10 host. All of that using  your IP addresses set in your shared local subnet, that will work no matter if you have a VPN stablished or not, if you access to internet through your Wi-fi adapter or trhough your ethernet cable.

Ah... one last advice. If you want to exchange files between Windows 10 and your virtual machines, a very useful and simple option is using [WinSCP](https://winscp.net/eng/download.php). It's free and it works really well.

Well, surely there are other configurations... but this is the one that I use and has proved to be the more reliable. I hope you find it useful also. If I've avoid you any headache, this article will have been worthy.

<span style="font-family:Comic Sans MS,cursive;"><strong><em>¡Happy Coding!</em></strong></span>