Setting up Docker on Windows
Containers give developers a way to rapidly re-create their environment at the drop of a hat. Containers are coming to Windows really soon. Docker is a great tool to help you manage all of those magical containers. I recently set up Docker in my desktop and I lived to talk about it. Here’s the scoop:
- If you haven’t already, install Hyper-V
- Make sure you have an external Hyper-V switch.
- You can check using
Get-VMSwitch | where { $_.SwitchType -eq "External" }
- If none exist, create one. I named mine “docker”.
- You can check using
- Create a few helpful environment variables. If you don’t set them up, you’ll have to keep passing them as command line flags to docker and then you’ll get all kinds of mad.
HYPERV_VIRTUAL_SWITCH
- give this the name of the switch you created in 2.2MACHINE_STORAGE_PATH
- this is where your docker VMs are going to live. I usedG:\docker
.
- Add
C:\docker
to yourPATH
environment variable. - Directly download
docker-machine
from https://github.com/docker/machine/releases.- Scroll down to the “Downloads” section and grab the appropriate Windows executable.
- Once you download it, rename the file to
docker-machine.exe
(as opposed to whichever architecture specific file you have). - Copy
docker-machine.exe
intoC:\docker
.
- Download the
docker
client from https://github.com/docker/docker/releases.- Same deal as before - scroll down to “Downloads” and get the appropriate windows executable.
- Rename the file to
docker.exe
. - Copy
docker.exe
intoC:\docker
.
- Open up some kind of terminal and execute
docker-machine create -d hyperv dockervm
. Because of an existing issue in docker-machine, this needs to be an administrator terminal. - You can execute
docker-machine env dockervm
to find out how to connect to this VM. It’s going to tell you something like…& "C:\docker\docker-machine.exe" env default | Invoke-Expression
. Run that. This just sets up yourdocker
environment so you can do more stuff. Trust me, this confusion only happens once.
At this point, you’re pretty much all set. You can run docker run hello-world
and you’ll get a message that you’ve set everything up and life is good. You can also connect directly to that VM you just created using docker-machine ssh dockervm
. [caption id=“attachment_996” align=“aligncenter” width=“1024”] Awww… it’s a whale![/caption] Yeah, it’s Linux. But right now, that’s how you’re going to be working with containers. This is just to get started, too. There’s a lot more than you can do with Docker and better Windows support is on the way (both from Docker and Microsoft’s support for containers). Getting started with Docker is the first step. You can try out Windows containers today on Windows running either 2016 preview builds or Windows 10 (10.0.10586 or later). Check out the Windows Container Quick Start for more