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:

  1. If you haven’t already, install Hyper-V
  2. Make sure you have an external Hyper-V switch.
    1. You can check using Get-VMSwitch | where { $_.SwitchType -eq "External" }
    2. If none exist, create one. I named mine “docker”.
  3. 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.
    1. HYPERV_VIRTUAL_SWITCH - give this the name of the switch you created in 2.2
    2. MACHINE_STORAGE_PATH - this is where your docker VMs are going to live. I used G:\docker.
  4. Add C:\docker to your PATH environment variable.
  5. Directly download docker-machine from
    1. Scroll down to the “Downloads” section and grab the appropriate Windows executable.
    2. Once you download it, rename the file to docker-machine.exe (as opposed to whichever architecture specific file you have).
    3. Copy docker-machine.exe into C:\docker.
  6. Download the docker client from
    1. Same deal as before - scroll down to “Downloads” and get the appropriate windows executable.
    2. Rename the file to docker.exe.
    3. Copy docker.exe into C:\docker.
  7. 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. Make a new thing, internet robot!
  8. 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 your docker 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! 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