54

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 ?

Josh
  • 2,142
  • 2
  • 23
  • 20
Chris
  • 1,692
  • 2
  • 17
  • 21
  • 1
    I have edited [my answer below](http://stackoverflow.com/a/29728993/6309), after Ed's feedback: installing docker-compose directly in boot2docker (instead of trying to run it in a container) seems the more robust solution. – VonC Jun 08 '15 at 15:55

10 Answers10

60

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.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 5
    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 – thaJeztah Apr 20 '15 at 20:35
  • 1
    @thaJeztah true. In my case, `docker-compose` is a submodule of my repo (https://github.com/VonC/b2d), and I wanted to checkout that `docker-compose` submodule to a specific tag, in order to build a stable version. – VonC Apr 20 '15 at 20:36
  • 1
    Strange, my boot2docker VM won't persist the docker-compose installation even after running the second step `echo 'su...` – Anthony F. Jun 18 '15 at 15:53
  • 1
    @AnthonyF. Indeed. I only tested the image option. You can mention it in issue 603, although after reading https://github.com/boot2docker/boot2docker/issues/603#issuecomment-110033929, I would wait for docker and boot2docker 1.7. – VonC Jun 18 '15 at 16:53
  • 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. – Ross Jul 30 '15 at 10:02
  • Docker Compose is included in Docker Desktop for Windows, which is a paid product. Some developers need to install docker-compose without installing Docker Desktop for Windows, – Michael Freidgeim Dec 16 '22 at 05:19
  • @MichaelFreidgeim True. A lot has changed since I started this answer in 2015. – VonC Dec 16 '22 at 07:13
13

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 commandline or 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.

Michael Freidgeim
  • 26,542
  • 16
  • 152
  • 170
jonashackt
  • 12,022
  • 5
  • 67
  • 124
12

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.

Ross
  • 1,641
  • 3
  • 15
  • 16
10

You can install docker-compose on Windows with pip:

pip install -U docker-compose
Peter
  • 1,658
  • 17
  • 23
  • 1
    The command for me was actually: python -m pip install -U pip – Ev Haus May 09 '15 at 17:26
  • 4
    You can indeed, but when running `docker-compose up` it raises `ImportError: No module named 'fcntl'` – Mathieu Dhondt May 14 '15 at 06:27
  • 1
    This solution doesn't work. The installed package is unusable (I get the same error as @LaundroMat). – André Caron May 19 '15 at 20:03
  • 3
    I was able to use docker-compose successfully using windows and Babun. Simply follow [this guide](http://py-generic-project.readthedocs.org/en/latest/installing.html#babun) to install *pip* and *babun,* and then call `pip install -U docker-compose` – mcmil May 20 '15 at 16:08
  • 1
    @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). – Mathieu Dhondt May 22 '15 at 08:53
  • 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. – Rafael Slobodian Jun 08 '15 at 10:54
  • @mcmil I'm also getting the `ImportError` when running docker-compose from inside babun. – Henrik Heimbuerger Jul 12 '15 at 13:34
  • This answer is only valid for Unix machines, doesn't work on windows unless you have a fcntl equivalent installed – Maxim Jul 20 '15 at 18:12
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.

fayndee
  • 129
  • 6
  • 1
    boot2docker has native support on Windows now – RadiantHex May 04 '15 at 00:34
  • 1
    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' – Sowry May 07 '15 at 11:31
  • 2
    This works for me with bash/Cygwin: `alias docker-compose="docker run -v \"$(pwd)\":/app dduportal/docker-compose:latest"` – user11153 May 20 '15 at 13:03
  • 1
    Running in a container might not always work. See [my edited answer below](http://stackoverflow.com/a/29728993/6309), after Ed's feedback. – VonC Jun 08 '15 at 15:54
5

boot2docker versions >= 1.7.0 have 64 bits userspace. This means that prebuilt binaries from their github repository are working out of the box.

I have used the information in VonC's answer above to write a script that downloads the latest version (or a specific version, see the commented part in the code) and persists it. It will only download the file once, but it will put it on the path on every startup of boot2docker.

Instructions:

  1. boot2docker ssh from any terminal.
  2. paste the script and press enter.
  3. exit and then run boot2docker restart && boot2docker ssh
  4. When the box is restarted, run docker-compose to see that it responds with its command list.

On Windows, the boot2docker restart command has a tendency to fail the first time. But it is just to run that command again.

echo 'if [ ! -f /var/lib/boot2docker/etc/docker-compose-`uname -s`-`uname -m` ]; then
    echo "Download docker-compose..."
    # Download latest version
    curl -L https://github.com/docker/compose/releases/download/$(curl -s -L https://github.com/docker/compose/releases/latest | \
        grep -Eo -m 1 docker/compose/releases/tag/\([0-9.]*\) | \
        grep -o [0-9.]*)/docker-compose-`uname -s`-`uname -m` \
    > /var/lib/boot2docker/etc/docker-compose-`uname -s`-`uname -m`
    # Download fixed version
    # curl -L https://github.com/docker/compose/releases/download/1.3.1/docker-compose-`uname -s`-`uname -m` \
    # > /var/lib/boot2docker/etc/docker-compose-`uname -s`-`uname -m`
    echo "Done!"
fi
echo "Install docker-compose on path..."
cp /var/lib/boot2docker/etc/docker-compose-`uname -s`-`uname -m` /usr/local/bin/docker-compose &&
chmod +x /usr/local/bin/docker-compose
echo "Done!"
' | sudo tee /var/lib/boot2docker/bootlocal.sh > /dev/null && \
sudo chmod +x /var/lib/boot2docker/bootlocal.sh
Community
  • 1
  • 1
D. Josefsson
  • 1,052
  • 7
  • 21
4

Things have progressed and lately, I've had the most success with the following method, which allows you to run it natively on Windows, by using Docker.

First, you'll want to install the Docker CLI for Windows:

curl -L https://get.docker.com/builds/Windows/x86_64/docker-latest.exe > /usr/bin/docker
chmod +x /usr/bin/docker

Next, build the docker-compose image from the Github repository:

docker build -t docker-compose github.com/docker/compose

Then, simply set up an alias to run the container:

alias docker-compose='docker run --rm -ti -v /var/run/docker.sock:/var/run/docker.sock -v `pwd`:`pwd` -w `pwd` docker-compose'

I've been using this for a while now and haven't ran into any problems -- the functionality is exactly what you'd expect as if using the binary natively, you just need to make sure your shared folders are mapped correctly into the B2D/Docker-Machine VM. I find it easiest to mirror the paths in the VM as they are on the host so my docker-compose.yml file isn't quite so confusing.

CashIsClay
  • 2,182
  • 18
  • 18
4

I got success following this issue on github

  • install docker-machine;
  • install python (3.4.3 worked fine)
  • install pip;
  • after pip... run this command to install docker-compose:

    `pip install git+git://github.com/docker/compose.git`
    

Not believing? watch this proof

LiberQuack
  • 151
  • 1
  • 5
3

https://github.com/docker/compose/releases/tag/1.5.0rc3 "Compose is now available for Windows."

FDisk
  • 8,493
  • 2
  • 47
  • 52
2

This has been my go-to answer for getting Compose installed inside of boot2docker. If anyone would like to entertain VonC's suggestion to run Compose against their host's Docker host from within a container, I've created a journeyman developer's container that follows Compose's guidelines and is easy to install and run.

If you have a Bourne shell-like environment on Windows, you can simply run:

curl -L https://git.io/vuEqk -o /usr/local/bin/room
chmod +x /usr/local/bin/room

You can start a container on any path and take it from there by simply running:

room

You can optionally pass command arguments, so if you find yourself in a working directory that has a Compose configuration file, this would suffice to get everything up and running:

room docker-compose up

If your missing a supportive shell environment, installing one of the Git distributions for Windows which include the Git Bash prompt would suffice or you can directly use the prompts from one of either MinGW or Cygwin. If not, you can always SSH into your Docker Machine and install there.

Filip Dupanović
  • 32,650
  • 13
  • 84
  • 114