How to install docker-compose on Windows

82,986

Solution 1

Update 2021: docker-compose has been rewritten in Go, and is now a docker command docker compose

As such, there is no longer the need to "install" it.
See docker compose.


Update 7th of november 2018:

On desktop systems like Docker for Mac and Windows, Docker Compose is included as part of those desktop installs.

Accordingly to the documentation, Docker for Windows and Docker Toolbox already include Compose along with other Docker apps, so most Windows users do not need to install Compose separately.


Update 2017: this is now officially managed (for Windows 10 supporting Hyper-V) with "Docker for Windows".
See "Install Docker for Windows".
It does have a chocolatey installation package for Docker, so:

choco install docker-for-windows 
# or
choco upgrade docker-for-windows 

Again, this requires a 64bit Windows 10 Pro, Enterprise and Education (1511 November update, Build 10586 or later) and Microsoft Hyper-V.

For other Windows, you still need VirtualBox + Boot2Docker.


Update: docker compose 1.5 (Nov 2015) should make it officially available for Windows (since RC2).

Pull requests like PR 2230 and PR 2143 helped.
Commit 13d5efc details the official Build process for the Windows binary.


Original answer (Q1-Q3 2015).

Warning: the original answer ("docker-compose in a container") below seems to have a bug, according to Ed Morley (edmorley).

There appear to be caching issues with the "docker-compose in a container" method (See issue #6: "Changes to docker-compose.yml and Dockerfile not being detected")

Ed recommends:

As such for now, running the Python docker-compose package inside boot2docker seems to be the most reliable solution for Windows users (having spent many hours trying to battle with the alternatives).

To install docker-compose from PyPI, run this from inside boot2docker:

docker@boot2docker:~$ 
tce-load -wi python && curl https://bootstrap.pypa.io/get-pip.py | \
  sudo python - && sudo pip install -U docker-compose

To save having to run the above every time the boot2docker VM is restarted (since changes don't persist), you can use bootlocal.sh like so:

docker@boot2docker:~$ 
echo 'su docker -c "tce-load -wi python" && \
  curl https://bootstrap.pypa.io/get-pip.py | \
  python - && pip install -U docker-compose' | \ 
  sudo tee /var/lib/boot2docker/bootlocal.sh > /dev/null && \
  sudo chmod +x /var/lib/boot2docker/bootlocal.sh

(The su docker -c gymnastics are required since tce-load cannot be run as root, and bootlocal.sh is run as root. The chmod of bootlocal.sh should be unnecessary once #915 is fixed.
Add -a to the tee command if you need to append, rather than overwrite bootlocal.sh.)

If you wish to use a pre-release version of docker-compose, then replace pip install -U docker-compose with pip install -U docker-compose>=1.3.0rc1 or equivalent.


Original answer:

I also run docker-compose (on Windows boot2docker) in a image by:

From there, a 'dc up' or 'dc ps' just works. On Windows. With boot2docker 1.6.

Solution 2

There is one more solution of running docker-compose under Windows using Babun (a famous port of Cygwin shell with all kinds of enhancements, including a package manager).

Here is how:

1.) Install Babun 2.) Open it and instal required dependencies for Python and Pip:

pact install python-setuptools 
pact install libxml2-devel libxslt-devel libyaml-devel
curl -skS https://bootstrap.pypa.io/get-pip.py | python
pip install virtualenv
curl -skS https://raw.githubusercontent.com/mitsuhiko/pipsi/master/get-pipsi.py | python

3.) Finally run

pip install -U docker-compose

The solution is not mine, taken from here: http://habrahabr.ru/post/260329/

I have a strong opinion, that docker-compose must be installed on a host, not a boot2docker VM, so you don't need to ssh all the time.

Solution 3

The easiest way to install Docker Compose (and Docker) on Windows, is to use the chocolatey (a package manager for Windows) package docker-compose, which should be installed after the package docker. This will free you from the many obstacles, when installing it manually and gives you an easy way to update your installation.

If you´re not familiar with chocolatey, just install it - e.g. on a administrative commandline with:

@powershell -NoProfile -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"

Now that chocolatey is installed, the only thing that´s left is to fire up a administrative Powershell and do:

choco install docker
choco install docker-compose

As a sidenote: You don´t need Boot2Docker anymore to run Docker on Windows - Docker natively support´s Windows for some time now. So no need for that anymore.

Solution 4

You can install docker-compose on Windows with pip:

pip install -U docker-compose

Solution 5

It seems they haven't added native support into the Windows version of Boot2Docker yet.

So for the moment, you can use docker-compose as how you've done with fig previously: run it as a docker container.

Share:
82,986
Chris
Author by

Chris

Computer science is very nice

Updated on July 09, 2022

Comments

  • Chris
    Chris almost 2 years

    If I type the following commands in boot2docker as shown on the docker website:

    curl -L https://github.com/docker/compose/releases/download/1.1.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
    chmod +x /usr/local/bin/docker-compose
    

    When I type the following commands to check if the installation was successful, I get:

    /usr/local/bin/docker-compose: line 1: syntax error: unexpected newline
    

    So, how can I install docker-compose on boot2docker ?

    • VonC
      VonC about 9 years
      I have edited my answer below, after Ed's feedback: installing docker-compose directly in boot2docker (instead of trying to run it in a container) seems the more robust solution.
  • thaJeztah
    thaJeztah about 9 years
    You don't even have to clone the repo, simply do docker build -t docker-compose github.com/docker/compose and docker will clone and build the repository
  • VonC
    VonC about 9 years
    @thaJeztah true. In my case, docker-compose is a submodule of my repo (github.com/VonC/b2d), and I wanted to checkout that docker-compose submodule to a specific tag, in order to build a stable version.
  • RadiantHex
    RadiantHex about 9 years
    boot2docker has native support on Windows now
  • Sowry
    Sowry about 9 years
    alias docker-compose='docker run --rm -it \ -v $(pwd):/app \ -v /var/run/docker.sock:/var/run/docker.sock \ -e COMPOSE_PROJECT_NAME=$(basename $(pwd)) \ dduportal/docker-compose'
  • Ev Haus
    Ev Haus about 9 years
    The command for me was actually: python -m pip install -U pip
  • Mathieu Dhondt
    Mathieu Dhondt about 9 years
    You can indeed, but when running docker-compose up it raises ImportError: No module named 'fcntl'
  • André Caron
    André Caron about 9 years
    This solution doesn't work. The installed package is unusable (I get the same error as @LaundroMat).
  • user11153
    user11153 about 9 years
    This works for me with bash/Cygwin: alias docker-compose="docker run -v \"$(pwd)\":/app dduportal/docker-compose:latest"
  • mcmil
    mcmil about 9 years
    I was able to use docker-compose successfully using windows and Babun. Simply follow this guide to install pip and babun, and then call pip install -U docker-compose
  • Mathieu Dhondt
    Mathieu Dhondt about 9 years
    @mcmil For the record, I keep having the same problem unfortunately. (It's not that big of a problem for me, but it's of course a pity).
  • Rafael Slobodian
    Rafael Slobodian about 9 years
    I was able to install docker-compose with pip, running via cygwin and I have almost no issues running it (not experiencing this ImportError). The issue I'm having is when trying to map volumes to my container via the compose yml. Since docker fails silently when it can't find the source path of a volume mapping, all it does is create the destination paths as empty folders. I suspect my source paths are translated incorrectly by either cygwin or docker-compose. I'm stuck.
  • VonC
    VonC about 9 years
    Running in a container might not always work. See my edited answer below, after Ed's feedback.
  • Anthony F.
    Anthony F. about 9 years
    Strange, my boot2docker VM won't persist the docker-compose installation even after running the second step echo 'su...
  • VonC
    VonC about 9 years
    @AnthonyF. Indeed. I only tested the image option. You can mention it in issue 603, although after reading github.com/boot2docker/boot2docker/issues/…, I would wait for docker and boot2docker 1.7.
  • Jonathan Geisler
    Jonathan Geisler almost 9 years
    @mcmil I'm also getting the ImportError when running docker-compose from inside babun.
  • Maxim
    Maxim almost 9 years
    This answer is only valid for Unix machines, doesn't work on windows unless you have a fcntl equivalent installed
  • Ross
    Ross almost 9 years
    docker-compose is a tool which must be installed on a host machine, not on any virtual host. At the time of writing there already exist working solutions for Windows. See below.
  • VonC
    VonC almost 9 years
    @RossIvantsiv I agree and have upvoted your answer. For my use case, using docker-copose through a container was enough and wa working.