According to Microsoft technology analyst Mary Jo Foley and a leaked Microsoft internal slide deck, Windows Server vNext will include a containerized deployment option. Specifically, Microsoft is hard at work bringing Docker to Windows.
Of course, you probably have these questions on your mind:
- What the heck is Docker, and why is it considered to be so revolutionary?
- I thought Docker was for Linux?
Let’s address both of those questions straightaway. By the conclusion of this article, I want you to have a clear picture of what Docker is, how it works, and how it may factor into future Windows OS versions.
Docker intoduction ^
I want us to dive into the tech as quickly as possible, so I’ll make this definition fast. According to the Docker web site, Docker is and open-source platform for building and distributing applications. In a Docker infrastructure, your applications run in totally isolated, trimmed-down containers that are protected from other containers as well as your base operating system.
Docker, I think, has some advantages over Microsoft, Citrix, and other app virtualization vendors. The open-source angle is nice from a security and cost standpoint. Also, Docker containers make it simple to deploy complex applications (even n-tier apps such as a WordPress content-management pod) along with all their dependencies. Docker accomplishes this through modularization. To wit, Docker consists of two primary components:
- Docker Engine: Lightweight runtime environment and container packaging tool
- Docker Hub: Public container repository
The challenge for us as Microsoft professionals, of course, is that Docker was conceived to run in the Linux world. This makes sense to me because most software in Linux is open-source and more accessible from a low level than is proprietary software such as Microsoft’s or Apple’s. That said, Microsoft sees enough business value in Docker that it won’t be too long before we see a native Windows Docker engine.
For now, though, we have to settle for a virtual machine-based Docker implementation that isn’t as lean as native Docker but is certainly better than nothing.
Installing Docker on Windows ^
In this case study, we’ll install Docker for Windows (such as it is in early 2015) and deploy a pre-made WordPress content management system (CMS) container as a proof of concept.
The first step is to download and install the latest Docker for Windows build from its GitHub repository. As you can see in the following figure, Docker for Windows uses a traditional Windows installer.
Installing Docker is straightforward.
If you accept the installation defaults (which I highly suggest you do), the software gives you the following three components:
- Boot2Docker management tool and ISO: This is the Docker administration command-line interface (CLI).
- VirtualBox: We need the core of the Oracle VirtualBox VM desktop virtualization product to allow us to run the core Linux code from inside Windows.
- MSYS-git UNIX tools: The Docker Hub will pull containers from public Git repositories, so we need to have client tools available on our system.
You’re recommended to restart Windows before running Docker for the first time, but I was able to proceed without rebooting.
Next, double-click the pretty Boot2Docker Start Desktop icon to start the Boot2Docker management tool. You’ll be prompted to allow VirtualBox to bind two virtual network interfaces, and before long you’ll see a decidedly Linux-y command prompt ,as shown in the following screen capture.
Docker for Windows gives us a pretty icon and a command-line interface. Is that an oxymoron?
Testing Docker with Hello World container ^
To verify that Docker is functioning correctly, run the following command from the Boot2Docker client:
docker run hello-world
If all goes well, you’ll see a bunch of explanatory text on your screen. The part that I find the most interesting is the following list, which explains what just happened on your Windows box:
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(Assuming it was not already locally available.)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
So what’s happening is that when we try to start a container with the docker run command, our Boot2Docker client contacts the Docker runtime daemon (what we might consider to be a service in Windows) to check whether the container is locally available. In our case, the Docker daemon runs inside a VirtualBox VM.
If the container isn’t available locally, the daemon pulls the container from the Docker Hub and fires it up. Neat!
As you can see in the following screenshot, my Docker for Windows session spawns a bunch of Oracle VirtualBox processes, but it added nothing to my Windows box’s actual service list. When you exit Docker, those processes go away.
All we see of Docker at the Windows OS level is the VirtualBox VM that runs the Docker components.
That having been said, as you can see in the following screenshot, Docker for Windows does permanently install Oracle VirtualBox on your host system, so be prepared for that. Again, once Windows supports Docker natively, we won’t need a Linux-based virtual machine to act as a shim.
In Windows, the Docker engine runs in an honest-to-goodness Linux virtual machine inside Oracle VirtualBox.
Installing a WordPress container ^
Hello World is fine for starters, but I want to try out a truly impressive container. How about WordPress? As you may or may not know, WordPress is a blog/content management system that runs in a LAMP (Linux, Apache web server, MySQL database, PHP) stack.
We can run docker images at any time in Boot2Docker to see what containers are available locally:
docker@boot2docker:~$ docker images
REPOSITORY TAG IMAGE ID CREATED
hello-world latest e45a5af57b00 12 weeks ago
You’ll find that several Docker community members contributed their own WordPress Docker containers. Of course, the standard rules apply concerning how much you want to trust publically accessible software repositories. In the future, I’m sure that we Windows administrators will build our own Docker images and host them on private repositories.
Anyway, I chose Eugene Ware’s WordPress build because (a) it works; and (b) he uses nginx as the web server instead of Apache.
First we need to clone Eugene’s GitHub repo, which makes all the WordPress containers available to our Windows system:
git clone https://github.com/eugeneware/docker-wordpress-nginx.git
After Docker downloads all the bits, you’ll need to use cd to switch your focus into the local repository:
Next, we’ll build the containers:
sudo docker build -t="docker-wordpress-nginx" .
Don’t forget about the space and the dot at the end of the preceding command string!
Once the build completes, our final step is to start the containers and map TCP port 8081 in Windows to port 80 in the Docker container:
docker run -d -p 8081:80 docker-wordpress-nginx
As you can see in the following screenshot, I connected to WordPress instantly after pointing my browser to the VirtualBox virtual network interface’s private IP address (http://192.168.59.103:8081).
This is a fully portable and containerized WordPress installation.
Cleaning up the environment ^
You’ve heard the expression RTFM (“Read the Friendly Manual!”) before, right? To that point, you should spend time reading the Docker User Guide. Also, you can get a list of all available Docker commands from the CLI by running:
To stop a container, you need to know its name, so run the following command and take note of the image name. I took the liberty of formatting the output in a more eye-friendly way:
CONTAINER ID: bbf255c32fd8
COMMAND: /bin/bash /start.sh
CREATED: 22 minutes ago
STATUS: Up 22 minutes
PORTS: 3306/tcp, 0.0.0.0:8081->80/tcp
I’m not sure what’s up with that wacky “romantic_mcclintock” name, to be perfectly honest with you. Perhaps it’s a tongue-in-cheek, globally unique identifier? Anyway, to stop our WordPress/nginx image, let’s run the appropriate command:
docker stop romantic_mcclintock
Refreshing my browser on my containerized WordPress site gives a 404 error, which is perfectly expected.
So what do you think of Docker? Even though its current implementation on Windows isn’t “true” Docker because we are hosting the Docker environment inside a Linux virtual machine, I hope that you were as impressed with its capabilities as I am.
Imagine a Windows Server in which the operating system itself runs in a tidy container. Think of how much more modular, granular, and secure this setup would be. Any applications we deploy on top of Windows also run in isolated containers. Yes—this is why Docker and application virtualization caught Microsoft’s attention so thoroughly in 2014. See you next time.