JVM microservices – how to run Docker containers on Windows
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.
Glossary
- GIT-SCM – Git For Windows project, containing
git
,bash
and otherLinux
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
- Impossible to skip bundled GIT SCM installation, even when newer version already installed
- 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 usingc:\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 fromC:\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 fromArch Linux
distributive- Possibility to install arbitrary tools not included into
MSYS2
distributive - Possibility to upgrade
MSYS2
core from command line
- Possibility to install arbitrary tools not included into
Installation steps
- Run installer from https://msys2.github.io/ and follow instructions
- Use
d:\opt\msys
as a destination folder - After installation is completed add
d:\opt\msys\usr\bin
toPATH
environment variable
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 setting environment variable HOME
to preferred value.
Setup Docker Toolbox
Installation steps
- Run
Windows
installer from https://www.docker.com/docker-toolbox and follow instructions - Use
d:\opt\docker
as a destination folder - After installation is completed, uninstall GIT SCM via Control Panel, we will use
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`.
- Run installer from https://conemu.github.io/ and follow instructions, alpha releases can be used
- Create
ConEmu
task for runningbash
console and run it on program startup
- Create new consoles inside single
ConEmu
window
- Integrate with
Windows
shell, environment variableCHERE_INVOKING
forcesMSYS2
to use current directory as a working directory for newbash
instance
Verify that everything works
- Start
ConEmu
program (should start withbash
console running inside new tab) - Open new console in
ConEmu
withCtrl+X
hotkey, this is just to checkCtrl+X
works - Go to
/d/opt/docker/
folder and run./start.sh
there - Execute
docker run hello-world
command - 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: https://hub.docker.com For more examples and ideas, visit: https://docs.docker.com/userguide/
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 defaultVirtualBox
VM$ docker-machine start default
– start defaultVirtualBox
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
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.
P.S.
This is the first post about JVM
based projects based on microservice architecture, mostly related to Windows
specific features.
Next post will explain how to create and run sample project using environment described in this guide.
Stay tuned.
Reference: | JVM microservices – how to run Docker containers on Windows from our JCG partner Evgeny Shepelyuk at the jk’s blog blog. |