如何在 Windows 上安装 docker-compose

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29289785/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 19:00:56  来源:igfitidea点击:

How to install docker-compose on Windows

windowsdockerboot2dockerdocker-compose

提问by Chris

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

如果我在 boot2docker 中键入以下命令,如 docker 网站上所示:

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 ?

那么,如何在 boot2docker 上安装 docker-compose 呢?

回答by VonC

Update 7th of november 2018:

2018 年 11 月 7 日更新:

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

在 Docker for Mac 和 Windows 等桌面系统上,Docker Compose 包含在这些桌面安装中。

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

根据文档Docker for WindowsDocker Toolbox已经包含 Compose 以及其他 Docker 应用程序,因此大多数 Windows 用户不需要单独安装 Compose。



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 chocolateyinstallation package for Docker, so:

2017 年更新:现在通过“Docker for Windows”正式管理(对于支持 Hyper-V 的 Windows 10)。
请参阅“为 Windows 安装 Docker”。
它确实有一个用于 Docker巧克力安装,所以:

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.

同样,这需要 64 位 Windows 10 专业版、企业版和教育版(1511 年 11 月更新,Build 10586 或更高版本)和 Microsoft Hyper-V。

For other Windows, you still need VirtualBox + Boot2Docker.

对于其他 Windows,您仍然需要 VirtualBox + Boot2Docker。



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

更新:docker compose 1.5(2015 年 11 月)应使其正式可用于 Windows(自 RC2)。

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

PR 2230PR 2143等拉取请求有所帮助。
Commit 13d5efc详细介绍了 Windows 二进制文件的官方构建过程。



Original answer (Q1-Q3 2015).

原始答案(2015 年第一季度至第三季度)。

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

警告:docker-compose根据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")

“容器中的 docker-compose”方法似乎存在缓存问题(请参阅问题 #6:“未检测到对 docker-compose.yml 和 Dockerfile 的更改”

Ed recommends:

埃德建议

As such for now, running the Python docker-composepackage inside boot2dockerseems 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-compose内部运行 Python包boot2docker似乎是 Windows 用户最可靠的解决方案(花了很多时间试图与替代方案作斗争)

要从 PyPI 安装 docker-compose,请从内部运行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 boot2dockerVM is restarted (since changes don't persist), you can use bootlocal.shlike so:

为了避免每次boot2docker重新启动 VM 时都必须运行上述命令(因为更改不会持续存在),您可以bootlocal.sh像这样使用:

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 -cgymnastics are required since tce-loadcannot be run as root, and bootlocal.shis run as root. The chmodof bootlocal.shshould be unnecessary once #915is fixed.
Add -ato the teecommand 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-composewith pip install -U docker-compose>=1.3.0rc1or equivalent.

su docker -c体操是必需的,因为tce-load不能作为 运行rootbootlocal.sh而是作为 运行root。一旦#915被修复,chmodofbootlocal.sh应该是不必要的。如果需要追加,请 添加到命令中,而不是覆盖。)
-ateebootlocal.sh

如果您希望使用 docker-compose 的预发布版本,请替换pip install -U docker-composepip install -U docker-compose>=1.3.0rc1或等效的。



Original answer:

原答案:

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

我还docker-compose通过以下方式在图像中运行(在 Windows boot2docker 上):

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

从那里,' dc up' 或 ' dc ps' 就可以了。在 Windows 上。使用 boot2docker 1.6。

回答by Ross Ivantsiv

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).

还有一种使用 Babun(具有各种增强功能的 Cygwin shell 的著名端口,包括包管理器)在 Windows 下运行 docker-compose 的解决方案。

Here is how:

方法如下:

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

1.) 安装 Babun 2.) 打开它并安装 Python 和 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

3.) 最后运行

pip install -U docker-compose

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

解决方案不是我的,取自这里: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.

我有一个强烈的意见,docker-compose 必须安装在主机上,而不是 boot2docker 虚拟机上,所以你不需要一直 ssh。

回答by Peter

You can install docker-compose on Windows with pip:

您可以使用 pip 在 Windows 上安装 docker-compose:

pip install -U docker-compose

回答by D. Josefsson

boot2dockerversions >= 1.7.0have 64 bits userspace. This means that prebuilt binaries from their github repositoryare working out of the box.

boot2docker版本 >=1.7.0有 64 位用户空间。这意味着来自他们 github 存储库的预构建二进制文件是开箱即用的。

I have used the information in VonC's answer aboveto 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.

我已经使用上面 VonC 的回答中的信息编写了一个下载最新版本(或特定版本,请参阅代码中的注释部分)并保留它的脚本。它只会下载一次文件,但它会在每次启动boot2docker.

Instructions:

指示:

  1. boot2docker sshfrom any terminal.
  2. paste the script and press enter.
  3. exitand then run boot2docker restart && boot2docker ssh
  4. When the box is restarted, run docker-composeto see that it responds with its command list.
  1. boot2docker ssh从任何终端。
  2. 粘贴脚本并按回车键。
  3. exit然后运行 boot2docker restart && boot2docker ssh
  4. 当盒子重新启动时,运行docker-compose以查看它是否以其命令列表响应。

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

在 Windows 上,该boot2docker restart命令有第一次失败的倾向。但这只是再次运行该命令。

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

回答by fayndee

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

似乎他们还没有在 Boot2Docker 的 Windows 版本中添加本机支持。

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

因此,目前,您可以使用 docker-compose 作为您之前使用 fig 的方式:将其作为 docker container 运行

回答by jonashackt

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.

在 Windows 上安装 Docker Compose(和 Docker)的最简单方法是使用Chocolatey(Windows 的包管理器)包docker-compose,它应该在包docker之后安装。这将使您在手动安装时摆脱许多障碍,并为您提供一种更新安装的简单方法。

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:

现在安装了巧克力,剩下的唯一事情就是启动管理 Powershell 并执行以下操作:

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 Windowsfor some time now. So no need for that anymore.

旁注:你不再需要 Boot2Docker 来在 Windows 上运行 Docker - Docker 原生支持 Windows已经有一段时间了。所以没有必要了。

回答by CashIsClay

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.

事情取得了进展,最近,我使用以下方法取得了最大的成功,该方法允许您使用 Docker 在 Windows 上本地运行它。

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

首先,您需要为 Windows 安装 Docker CLI:

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:

接下来,从 Github 存储库构建 docker-compose 镜像:

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.

我已经使用它一段时间了,并没有遇到任何问题——该功能正是您所期望的,就像本地使用二进制文件一样,您只需要确保您的共享文件夹正确映射到B2D/Docker 机器虚拟机。我发现最容易镜像 VM 中的路径,因为它们在主机上,因此我的 docker-compose.yml 文件不会那么混乱。

回答by Thiago Martins

I got success following this issue on github

在 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`
    
  • 安装docker-machine
  • 安装python(3.4.3 工作正常)
  • 安装pip;
  • 在 pip... 之后运行这个命令来安装 docker-compose:

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

Not believing? watch this proof

不相信?看这个证明

回答by FDisk

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

https://github.com/docker/compose/releases/tag/1.5.0rc3“Compose 现在可用于 Windows。”

回答by Filip Dupanovi?

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 containerthat follows Compose's guidelines and is easy to install and run.

这是我在boot2docker. 如果有人愿意接受 VonC 的建议,即从容器内针对其主机的 Docker 主机运行 Compose,我已经创建了一个遵循 Compose 指南且易于安装和运行的熟练开发人员容器

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

如果你在 Windows 上有一个类似 Bourne shell 的环境,你可以简单地运行:

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:

您可以选择传递命令参数,因此如果您发现自己位于具有 Compose 配置文件的工作目录中,则这足以启动并运行所有内容:

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 MinGWor Cygwin. If not, you can always SSH into your Docker Machine and install there.

如果您缺少支持的 shell 环境,安装其中一个包含 Git Bash 提示的适用于 Windows 的 Git 发行版就足够了,或者您可以直接使用来自MinGWCygwin之一的提示。如果没有,您始终可以通过 SSH 连接到您的 Docker 机器并在那里安装。