Return to site

Run Docker On Windows Home

broken image


Windows Server 2016 is available now in an evaluation version. It lasts for 180 days and then you'll be able to upgrade to GA, which is expected in the new few weeks. So here's how to get Docker up and running natively and run a simple IIS website in a Docker container in Windows Server.

Download the Evaluation Version

  1. As the Docker documentation states. If you are using Docker Machine on Mac or Windows, your Engine daemon has only limited access to your OS X or Windows filesystem. Docker Machine tries to auto-share your /Users (OS X) or C: Users (Windows) direc.
  2. Oct 21, 2019 If you've ever tried to install Docker for Windows, you've probably came to realize that the installer won't run on Windows 10 Home.Only Windows Pro, Enterprise or Education support Docker.
  3. As the Docker documentation states. If you are using Docker Machine on Mac or Windows, your Engine daemon has only limited access to your OS X or Windows filesystem. Docker Machine tries to auto-share your /Users (OS X) or C: Users (Windows) direc.

Browse to the link above, select to download the ISO, and click on Register to continue:

Description I am using Docker version 1.12.5 on Windows 10 via Hyper-V and want to use container executables as commands in the current path. I built a Docker image that is running fine, but I hav. If you've ever tried to install Docker for Windows, you've probably came to realize that the installer won't run on Windows 10 Home.Only Windows Pro, Enterprise or Education support Docker.

You'll need to fill in the usual details, and then the 5GB download will start.

Create a Windows Server Core VM

Where we're going, we won't need server UIs. Use your preferred VM platform to create a new Virtual Machine, point it at the ISO you downloaded and start it up. When you get to the Windows Setup screen, choose one of the Server Core options:

I've chosen Datacenter Evaluation, but the important thing is not to choose a 'Desktop Experience' variant. They come with a UI and it's time you stopped using them with servers.

When the install finishes and the VM boots up, you'll be prompted to log in with a quaint text-based screen:

Install Containers Feature

The next few steps are from Microsoft's Windows Containers on Windows Server Quickstart, but condensed and/or expanded.

There are two parts to running Docker on Windows - first you need to install the Containers Windows feature. Server Core boots into a command prompt, so you need to run powershell and then:

(You can use Ctrl-V in PowerShell to paste in the commands).

It will install the feature and then tell you to reboot, which you do with:

When it's back online, you'll have the Containers feature and now you can install the Docker Engine.

Install Docker

All in PowerShell, download Docker, unzip it to Program Files and add it to your path:

Note the path for the docker.zip download - this is the Commercially Supported Docker Engine. As announced at Ignite, your Windows Server 2016 licence gives you support for Docker included

Now you can install Docker as a Windows Service and start it up:

Run Windows Update

Yes, you need to do this. The Evaluation ISO may only be a day old, but there are updates available. In Server Core you manage them by running sconfig which gives you a fun text menu:

Hit 6 to download and install updates, and when it asks you hit A to choose all updates, and then A again to install all updates.

Windows will probably restart, and after that it would be a good time to checkpoint your VM.

Run a Windows Container!

There are two Windows Base images on the Docker Hub - microsoft/nanoserver and microsoft/windowsservercore. We'll be using an IIS image shortly, but you should start with Nano Server just to make sure all is well - it's a 250MB download, compared to 4GB for Server Core.

Check the output and if all is well, you can run an interactive container, firing up PowerShell in a Nano Server container:

Note that the command is the standard Docker run command, and the hostname for the container is a random ID, just like with Docker on Linux.

If all goes well, you're ready for the big time.

Run IIS in Docker

The microsoft/iis image is based off Server Core and weighs in at a healthy 4GB compressed. If you're used to running Web servers in Docker from nginx:alpine (compressd size: 17MB) that may come as a shock, but actually it's not a showstopper.

The Windows Server Core Docker image is a fully-featured Windows Server OS, with support for MSI software installations, and the range of Server roles and features. Having a Docker image for that means you can containerize pretty much any existing workload. And because of Docker's smart image layering and caching, if you have 10 apps all based off Server Core, they'll all be using the same file for their 7GB read-only base layer.

One quirk though, is that IIS (and other server roles like MSMQ and SMTP) will be running as Windows Services, and when you start a Docker container it needs a foreground process to monitor. If the foreground process ends, the container will exit - even if there are Windows Services still running - so you need to run your container with a process for Docker to watch:

-d puts the container in the background and -p publishes the port, so you can hit port 80 and the host and Docker will route the traffic to the container.

The ping -t business is an ugly way of giving Docker something to watch. As long as the ping process runs, Docker will keep the container running in the background. The Microsoft guys are working on a neater solution, where you'll start a foreground process which Docker monitors, and the foreground process actually monitors the Windows Service, so you'll get a proper container healthcheck.

Okay, now you have IIS running in a Windows Server Core-based container in a Windows Server Core VM, with port 80 published so if you browse to your VM's IP address you'll see the IIS welcome screen:

Now you can package your own Windows apps by writing a Dockerfile based from the Microsoft images, which will look something like this - for an ASP.NET app (full ASP.NET, not Core):

And yes,

This changes everything.

When you follow my blog for a while you probably know that running Windows Containers on Windows 10 had some disadvantages compared to a Windows Server. On Windows 10 every Windows Containers has to be run in Hyper-V isolation mode.

Process Isolation

With the latest release of Docker Desktop on Windows 10 1809 you now can run Windows Containers in process isolation mode. What's the benefit you might think.

In the past process isolation was only possible with Windows Server. The Windows 10 operating system uses the same kernel, but with different settings. With this pull request https://github.com/moby/moby/pull/38000 that got merged into Docker 18.09.1 it is now possible to use it on Windows 10 as well.

  • You can start more Windows Containers on your machine as they consume less resources
  • Containers normally start faster than in hyperv isolation mode
  • You can 'see' the isolated processes and what they are doing

Visible container processes

Especially for developers this is a great enhancement, because you now can use tools like Task Manager, Process Monitor and others to inspect your container processes from the host. I've blogged How to find dependencies of containerized Windows apps about a year ago. Now you do not longer need to spin up a Windows Server VM to do that, your Windows 10 machine is all you need.

Let's try this out with a small web server I have created for the Chocolatey Fest conference last October that's running in a Windows Nanoserver 2019 container.

Open up a PowerShell terminal and start a Windows container with this command

The command will pull the Docker image from Docker Hub, starts the web server as a container and forwards port 8080 to it.

Now you can access the web server with your browser or by typing this command

The web server should show you a sweet photo and the name of the container stamped on it.

As you can see in the screen shot you can see the node.exe process in the Task Manager. If you have the Sysinternals Process Monitor installed you also can see what the containerized process is doing. This is great when you create an own Docker image from your or a 3rd-party app and something doesn't work as expected or the exe file just doesn't want to start inside the container.

Run Docker On Windows Home Key

Windows image version must match kernel version

The only caveat using the process isolation mode is that the Windows base image that is used for a Docker image must match the kernel of your Windows 10 machine.

I've tried process isolation on a Windows Insider 18xxx machine, but here you are out of luck and you have to run the 1809 images in default Hyper-V isolation mode.

Can I run Windows Containers in VirtualBox?

I run all these tests in VMware Fusion on my Mac, spinning up a Windows 10 1809 VM with Vagrant. You can try it yourself with the given Vagrantfile in the repo.

For a full Docker Desktop experience you need VMware Fusion as it provides nested virtualization. This is needed to activate Hyper-V in the Windows 10 VM. Docker Desktop runs fine in that VMware VM and you can try out Linux and Windows containers in it.

From time to time I get asked if people can also use VirtualBox. In the past I had to say 'no' you can't use a Windows 10 VM and then run Windows Containers in it. But with process isolation there is a first breakthrough.

Danger zone for early adopters

I've tried that with VirtualBox to see what happens. The installation of Docker Desktop works without a problem. When you start Docker Desktop for the first time the following error will appear

Sure, Hyper-V does not work in a VirtualBox VM, that's why the MobyLinuxVM could not be started. But now you can switch to Windows containers in the context menu.

Run Docker On Windows Home Windows

After a few seconds the Windows Docker engine is up and running. Open a PowerShell terminal and run the appetizer app as described above.

Run

Voila! It works.

Try something different with an interactive nanoserver container with a CMD shell

TL/DR

Beginning with Windows 10 1809 and Docker 18.09.1 you can use the more lightweight process isolation mode for Windows Containers. Linux Containers still need Hyper-V installed to run them in Docker Desktop.

Run Docker On Windows Homepage

If you liked this blog post please share it with your friends. You can follow me on Twitter @stefscherer.





broken image