Skip to content

Exploring Docker on Windows 10 Pro

For the past few months, Docker has been continuously updating and stabilizing their container services on windows.
However, since docker depends on Hyper-V, It’s currently only available on Windows 10 Pro and Windows Server 2016.

Although containers are becoming a “common methodology” in 2017, let me try and describe them briefly for those of you who are late to the party.

What is a container?

Programmers and Computer Scientists usually, believe it or not, try to simplify things as much as possible; especially when it comes to namings. By that, I mean that containers are named containers because that’s what they do. Their job is to simply “contain” a process and isolate it from other processes running on the Operating System. The process running in a container can only communicate with processes running in the same container, and the processes running outside the container cannot communicate with processes inside the container.

Commonly, containers are used in a way where each container run a single process or have a single functionality such as a web server, a database container, etc… and it is typical for us to see that process sharing its lifecycle with the container’s lifecycle. meaning that when the container starts, the service/process starts with it. And naturally, when the container is stopped, the service is stopped with it.

Why are containers useful?

The main use of containers is to help us isolate an application from the outside world. This could be helpful if we are willing to move this application around and/or copy it to multiple computers. To do so, we have to include all of the application’s dependencies in our container.
One would think that this is contradicting with my previous statement saying that a container should typically have a single functionality. However, this is a wrong assumption and the statement is still valid because of the nature of how containers can be inherited. In other words, the dependencies of our application can be (and are advisable to be) different containers.

Containers come in form of “Images”, where an image consists a set of instructions telling the host what commands to run and which, if any, other containers are needed to run this image. For example, if we are running a web app, our image file would typically contain an inheritance of an OS container, a web server container, a database container, and our app to be hosted upon them. We can think of containers like a class, where a host can instantiate many instances of this class and use them independently. And the class could be inheriting different classes. It is supposed to have all it needs to do its intended functionalities.

What is Docker then?

We can think of Docker (again with the naming thing) as a dock, where ships ship containers from remote locations (usually from docker hub) to our host (the dock).

Docker helps us manage containers on our system from getting their images to running and removing them.

Messing with Docker on Windows 10 Pro

First things first, as I mentioned in the introduction that I’m proud of (not really), that docker needs Hyper-V to run. Hence your computer needs to support Hardware Virtualization (most computers do nowadays).

You can download and install docker from here.

Once you install docker, it will tell you that it will turn on Hyper-V for you (if you don’t have it on). After that, your computer will restart and Docker will be up and running. You can tell so by noticing the cute whale icon next to the clock on your taskbar .

Open up PowerShell and type docker. This will show you the list of commands that you can use with docker.

The first natural thing to try is to run:

docker run hello-world

this will look for a container named hello-world. Don’t worry about not having it. Docker will look to the container Image locally. If it doesn’t exist, It will pull it from docker hub.

Once you’re done playing with the hello-world container (which unlike typical containers, it exists after the first run) you can remove it by typing:

docker rmi hello-world

This will remove the image completely from your system. If it’s stubborn and doesn’t want to leave, add the force parameter (-f) to the previous command:

docker rmi hello-world -f

This will show it who’s the boss.

Some interesting containers to try

As an IIS hater, the first container to try was *drum roll* NGINX.

It is no surprise. I use WAMP on windows (don’t judge me. not a big fan either). and I thought, yes! now I can run all those projects on NGINX instead of the windows version of apache added by WAMP.

NGINX is a good example because it will help me show you how containers that are supposed to be contained in a sandbox can be accessed by my host and how can I run all of my projects on NGINX while they exist on my host outside of the container. It’s pretty simple, all we need to do is to tell the container to map the container’s port 80 (web server, duh) to any port we want on the host. if the host’s port 80 is not used by other services like IIS or WAMP, we can map it.  Optionally, we can also tell the container to map a path on the host (outside the container) to the container. This is how I made NGINX read my project folders and thus the projects inside.

The command I ran was as following:

docker run --name nginx -p 8181:80 -v C:/wamp/www:/usr/share/nginx/html:ro -d nginx

Yes, it is as simple as it looks:
docker run nginx obviously checks if nginx image exists on your computer, if not, gets it from docker hub.

–name nginx is a name for your container instance. you can name it whatever you want. –name myNginx. or whatever.

-p 8181:80 is where the port mapping happens. I chose to map the container’s port 80 to my host as 8181. you can naturally choose whatever port you see fit. As long as it’s not being used by another process.

-v C:/wamp/www:/usr/share/nginx/html is where I tell the container to map my wamp projects folder to nginx’s projects folder. “:ro” stands for read only.

You can explore further options and customizations on the NGINX container’s official hub page here.

Other awesome containers that I’ve found and tried

Optional GUI

If you’re not a fan of powershell / CLI, you can download Kitematic. It’s an interface that will help you manage your containers on Docker.

(Docker were nice enough to include a shortcut to it: remember the cute whale icon I mentioned above? right click -> Kitematic).

Final Words

Containers are exciting to work with, and pretty awesome at doing their job. Docker is a container management service that helps us ship containers from or to the docker hub (or different remote locations).

Feel free to send a message if you had any thoughts, or questions regarding this topic, or share your thoughts by leaving a comment below.