Microservices is one of the loudest IT buzzwords, everybody’s anxious to try it. But what Linux and MacOS users get for free is not so easy in Windows. This guide shows how to setup Windows environment for running Docker containers, as a basis for microservice architecture projects.

  • GIT-SCM - Git For Windows project, containing git, bash and other Linux tools

  • Environment variables - Windows environment variables, assumed to be managed via Control Panel

In fact, Docker Toolbox for Windows comprises everything for running Docker containers because it is bundled with GIT-SCM project. Unfortunately the default installation has few drawbacks

  • No option for changing GIT SCM destination

  • Сommand line tools ain’t added to PATH environment variable

  • Impossible to configure additional git parameters unlike in original GIT-SCM installer

To overcome those and to achieve the better environment flexibility, I’ll explain in this guide a longer way, where all required software will be installed from separate bundles.

Following old habit I tend to avoid installation of tools that are planned to be used from command line to C:\Program Files\ folder. Instead, I’m using c:\opt, d:\usr, etc., i.e. folder name without spaces. This guide will highlight steps where software is planned to be installed in folder different from C:\Program Files\.

Setup MSYS2

MSYS2 is a basis project for GIT-SCM and provides advantages over GIT-SCM,

Advantages over GIT-SCM
  • More command line oriented, not limited to git usage

  • Symbolic link support

  • Built-in package manager pacman, ported from Arch Linux distributive

    • Possibility to install arbitrary tools not included into MSYS2 distributive

    • Possibility to upgrade MSYS2 core from command line

Installation steps
  1. Run installer from https://msys2.github.io/ and follow instructions

  2. Use d:\opt\msys as a destination folder

  3. After installation is completed add d:\opt\msys\usr\bin to PATH environment variable

HOME directory location

By default MSYS2 uses own directory for user home, so instead C:\Users\ your home will be located in d:\opt\msys\home folder. This behavior can be overridden by adjusting /etc/nsswitch.conf file.

Find and change line db_home: cygwin desc to db_home: windows desc.

Linux Tools Manuals

man command is not installed by default, but you can enable it using pacman tool.

$ pacman -S man-db

Setup Docker Toolbox

  1. Run Windows installer from https://www.docker.com/docker-toolbox and follow instructions

  2. Use d:\opt\docker as a destination folder

  3. Uncheck Git for Windows checkbox, we will use Linux tools from MSYS2 installed before

Setup ConEmu

MSYS2 provides possibility to run bash but as soon as you run many consoles you start to get lost in those floating windows. ConEmu comes to the rescue, providing comfortable tabbed interface for bash shells along with additional functionality improving command line experience and better integration on`Windows`.

  1. Run installer from https://conemu.github.io/ and follow instructions, alpha releases can be used

  2. Create ConEmu task for running bash console and run it on program startup

    ConEmu task for running MSYS2
    Figure 1. ConEmu task for running MSYS2
  3. Create new consoles inside single ConEmu window

    ConEmu single window settings
    Figure 2. ConEmu single window settings
  4. Integrate with Windows shell, environment variable CHERE_INVOKING forces MSYS2 to use current directory as a working directory for new bash instance

    ConEmu shell integration settings
    Figure 3. ConEmu shell integration settings
    ConEmu shell integration
    Figure 4. ConEmu shell integration

Verify that everything works

  1. Start ConEmu program (should start with bash console running inside new tab)

  2. Open new console in ConEmu with Ctrl+X hotkey, this is just to check Ctrl+X works

  3. Go to /d/opt/docker/ folder and run ./start.sh there

  4. Execute docker run hello-world command

  5. Check output, it should looks like below, refer to Docker Guide for latest actual information about the output

$ docker run hello-world

Hello from Docker.
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker Hub account:

For more examples and ideas, visit:

docker-machine tool

Docker Toolbox installs VirtualBox and creates own VM inside it named default. Although VM management can be performed via VirtualBox UI, there’s useful docker-machine tool. It allows to interact with VirtualBox VM from command line. Some useful commands are shown below.

  • $ docker-machine ls - list machines and their statuses

  • $ docker-machine stop default - stop default VirtualBox VM

  • $ docker-machine start default - start default VirtualBox VM

  • $ docker-machine help - for more information

Improve Git experience on Windows

If you plan to use git then pay attention to steps below, otherwise this section could be skipped.

Line endings

GIT-SCM as well as other sources advice to use core.autocrlf equals to true while working with git on Windows. Execute command below to set this parameter for all git repositories.

$ git config --global core.autocrlf true
Password caching

Working with remote repositories via HTTP / HTTPS requires entering user name password. It’s good to use credentials helper that caches passwords, so there no need to type them each time. For GitHub it’s easy and explained in this article. But this approach doesn’t fit well with BitBucket repositories.

Git Credential Manager for Windows project works fine with both GitHub and BitBucket, but currently it can be used only with git installed via GIT-SCM - track сorresponding issue.

The solution is to use Git Credential Manager for Windows predecessor that works fine with any git installation.

Branch name in shell promt

Add following to your ~/.bashrc to display Git branch name in shell promt.

. /usr/share/git/completion/git-prompt.sh

PS1='\[\033]0;$MSYSTEM:${PWD//[^[:ascii:]]/?}\007\]'    # set window title
PS1="$PS1"'\n'                                          # new line
PS1="$PS1"'\[\033[32m\]'                                # change color to green
PS1="$PS1"'\u@\h '                                      # user@host<space>
PS1="$PS1"'\[\033[33m\]'                                # change color to yellow
PS1="$PS1"'\w'                                          # current working directory
if test -z "$WINELOADERNOEXEC" ; then
  PS1="$PS1"'$(__git_ps1)'                              # bash function
PS1="$PS1"'\[\033[0m\]'                                 # change color to normal
PS1="$PS1"$'\n'                                         # new line
PS1="$PS1"'$ '                                          # prompt: always $

What’s next ?

This is the first post about JVM based projects based on microservice architecture, mostly related to Windows specific features.

Second post explains how to create and run sample JVM project using environment described in this guide.