How to install docker-compose on Windows

南楼画角 提交于 2019-11-28 03:24:04
VonC

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.

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.

You can install docker-compose on Windows with pip:

pip install -U docker-compose

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.

D. Josefsson

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

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.

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

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

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!