Configuring Windows for Docker Development

Docker makes it easy to run Linux software on servers and laptops, regardless of the underlying host operating system. Follow all of the steps below to configure Docker on Windows.

Step 1: Install Windows Subsystem for Linux (WSL)

Windows Subsystem for Linux (WSL) allows you to efficiently run Linux operating systems on Windows. Docker runs using its own Linux-based operating system. You can run other operating systems as well (e.g., Ubuntu).

  1. Press the Windows key, then search for “cmd”
  2. Right-click on the “Command Prompt,” then choose “Run as administrator”
  3. Type wsl --install
  4. After the installation finishes, restart your computer
  5. Press the Windows key, then search for and open “Ubuntu”
  6. When prompted, configure a Linux username and password

Note: If you get an error saying that “the virtual machine could not be started because a required feature is not installed,” then you may need to enable “Virtualization Technology” in the BIOS or UEFI settings of your PC.

Step 2: Configure Git and VSCode

I strongly recommend using Git to clone project starter files. This provides several major advantages over simply downloading a .zip file. First, Git gives control over the line-endings of files in a repository. By default, Windows uses CRLF line-endings, while Linux uses LF line-endings. You will get errors if certain files using CRLF line-endings are used in a Docker container, so it is important to configure Windows to use LF line-endings. Second, Git preserves file system permissions, which are also important when using files in Docker. Third, you can use Git to see the changes you have made to the starter files, which is extremely convenient for troubleshooting.

  1. Install VSCode, keeping the default settings. Then:
    • Open VSCode, then open the “Settings” tab by clicking the “Manage” gear in the bottom left
    • Search for “eol”
    • Change “eol” from “auto” to “\n” (i.e., LF line-endings)
  2. Install Git on Windows, keeping the default settings except:
    • Change the default editor used by Git to “Visual Studio Code”
    • Change the line ending conversions to “Checkout as-is, commit as-is”
  3. Install the VSCode GitHub Pull Requests and Issues extension
    • Restart VSCode to complete the installation

Note: If you already had Git installed, you likely accepted all of the default settings. Follow these steps to configure Git to use LF line-endings:

  1. Press the Windows key, then search for and open “Git Bash”
  2. Type git config --global core.autocrlf false

Step 3: Install Docker Desktop for Windows

Docker Desktop includes a user-interface for Docker, as well as the background processes used by Docker.

  1. Download and run the Docker Desktop installer for Windows
  2. Log out when prompted
  3. After logging back in, press the Windows key, then search for and open “Docker Desktop”

Note: You will know Docker is running when you see the Docker whale icon in the taskbar corner. If you don’t see the icon, simply reopen the “Docker Desktop” app.

Cheatsheet

At this point, Docker should be fully configured on your Windows PC. Here are some common operations:

Clone a Repository

You now have several ways to clone a Git repository. If you are familiar with the UNIX command line, I recommend cloning using Ubuntu, but any of the options listed below should work.

First, locate the Git repo’s URL on GitHub. Next, follow the instructions of your choice:

Clone using VSCode

On VSCode’s “Get Started” page (available under the “Help” menu), you should see a “Clone Git Repository” link. Click this link, and you will be prompted to enter the repo’s URL.

Clone using Git Bash

  1. Press the Windows key, then search for and open “Git Bash”
  2. Use the ls and cd commands to move to the folder you want to clone the repository into
  3. Type git clone REPOSITORY_URL

Clone using Ubuntu

  1. Press the Windows key, then search for and open “Ubuntu”
  2. Use the ls and cd commands to move to the folder you want to clone the repository into
    • For example, I moved to my desktop using: cd /mnt/c/Users/peter/Desktop
  3. Type git clone REPOSITORY_URL

Using Docker Commands

You can run Docker commands from the Windows Command Prompt, Window PowerShell, Git Bash, or Ubuntu. For example, run docker ps to list running containers, if any.