Recently I was doing some hackery for a project and really struggled getting docker off the ground and serving up a website from within a container. This particular project was on linux but actually docker can also run on Windows, using the “built in” functionality of Hyper V. Not one to be defeated I set out to get the project working on Docker for Windows!
Step 1 – Download Docker for Windows
You can grab a copy of the download from the Docker Store here. Be aware though that is only runs on Win 10 professional or enterprise, use docker tools for other operating systems.
Step 2 – Install it
The installation was very simple. There are two configuration options in the installer, two!
Switching between Windows and Linux containers is so trivial I would not have even included it as an option here.
The installer will run for a few minutes and then vanish so you need to find and run Docker for Windows. I found it in Windows 10 start menu as I didn’t go for the desktop shortcut. Docker should then start to spin up and give you a notification.
Unfortunately it doesn’t get very far and informs you that it needs the container and hyper-v features.
Click Ok and after a few minutes your PC will restart, no warning given!
Step 4 – Login
To “pull” images from the dockerHub you need to login. Create a free account and then login to your account from the tray icon. I found that I could login with either my email address of username but if I used my email address I then could not pull images from the dockerHub. If you find that you get errors pulling images from the DockerHub on Windows 10 Docker, make sure you have logged in with your username and not your email address.
Once logged in, you can also familiarise yourself with the toolbar menu, including the option for switching between Linux and Windows containers. You cannot run both at the same time! Switching is painless but does take a few minutes.
Step 5 – Pulling our first image
Docker images all start in the DockerHub. There are thousands of repositories, but for our first we will use the official microsoft images so make sure you are running in Windows container mode and not Linux.
You can pull the nanoserver image by opening command prompt and running
docker pull microsoft\nanoserver
This will download and extract the image.
Step 6 – Interacting
The nanoserver image is now downloaded and ready to run. We can check this with the command
The image is shown and has a unique hash reference (Image ID) that you can use to interact with the image. We can then use this ID to run a container with
docker run -it <image id> powershell
Running that command should drop you into an interactive powershell prompt inside the container. You can verify this by looking at your username and computername environment variables. We are in our first container!
Step 6 – Squash another bug!
If you are having a route around in this container you may notice that you cannot ping out to the internet and cannot ping the container from your PC. This is a bug because the installer does not add the neccessary routes to your PCs routing table! To fix this, use the command
route /P add 220.127.116.11 MASK 255.0.0.0 10.0.75.2
Credit to https://github.com/docker/for-win/issues/221
You should now be able to ping in and out of your container.
… In the next part we will use a dockerfile to do our first IaC (Infrastructure as Code).