Docker Compose on Windows with Python And Babon

Compose is a tool for defining and running complex applications with Docker. With Compose, you define a multi-container application in a single file, then spin your application up in a single command which does everything that needs to be done to get it running. It is the only tool in the Docker tool-chain, which doesn’t have a native binary for Windows in place right now and to get it up and running on Windows requires quite some work.

Using Babon and Python


The official compose documentation implies, that there is a python only way on not supported platforms. As a matter of fact, this is not totally true. Even the Python package relies on POSIX based commands which aren’t available on Windows. If you try to go down this road you will get surprisingly far, but will not finish. The only way to make it work is to use CygWin. For those of you, who don’t like it (like I don’t), there is a decent alternative called Babun. Babun is a turn-key CygWin distribution for developers and is very easy to install and maintain.

  • Download the installer ZIP archive from the Babun homepage. (~280MB)
  • Unzip the archive to a temporary folder.
  • Change to the unzipped folder and start the install.bat (this might take a while) When you’re finished, you can safely delete the temp folder.
  • The babun shell is now open, run the command: “babun update”
  • Change the default shell from zsh to bash if you prefer that by running the command: “babun shell /bin/bash”.
  • Edit ~/.bashrc to activate loading of ~/.bash_aliases. (scroll down a bit until you find the line: “#Aliases” and un-comment the if statement.
  • Install additional Python essentials:
    pact install python-setuptools 
    pact install libxml2-devel libxslt-devel libyaml-devel
    curl -skS | python
    pip install virtualenv
    curl -skS | python

This installed a bunch of python packages and the pipsi package manager to your Babun installation. Now you’re ready to actually install the docker compose python package:

pip install -U docker-compose

After everything got downloaded and installed, you can now use compose from Babun:

{ ~ }  » docker-compose --version                                                            
docker-compose 1.2.0

With the mapped directories it is easy to change to a temp folder on your windows drive (e.g. /d/temp/) and use compose. Make sure you have everything you need in your PATH variable (Hint: that is different now, e.g. just use:  PATH=$PATH\:/d/path/to/docker/exe ; export PATH ) and make sure to set your environment properly:

eval "$(docker-machine env)"

Now, you can go ahead and just use a very simple docker-compose.yml file, like the one Arun blogged about and you have a bunch of instances up and running without any further configuration or command line hacks.

Find the complete reference to the compose file format on the official Docker Website.

Using the Docker Image Workaround

If you want to, you can try to use the (unofficial) Docker Compose image and run it as a container locally. While this seems to be a solution, I couldn’t get this to work on plain Windows. Any pointer and ideas appreciated.

A Two Minute Babun Screencast

Have a look at a 2 minutes long screencast about Babon by @tombujok.

Markus Eisele

Markus is a Developer Advocate at Red Hat and focuses on JBoss Middleware. He is working with Java EE servers from different vendors since more than 14 years and talks about his favorite topics around Java EE on conferences all over the world. He has been a principle consultant and worked with different customers on all kinds of Java EE related applications and solutions. Beside that he has always been a prolific blogger, writer and tech editor for different Java EE related books. He is an active member of the German DOAG e.V. and it's representative on the iJUG e.V. As a Java Champion and former ACE Director he is well known in the community. Follow him on Twitter @myfear.
Notify of

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Newest Most Voted
Inline Feedbacks
View all comments
Back to top button