如何在 Windows 上安装 docker-compose [英] How to install docker-compose on Windows

查看:69
本文介绍了如何在 Windows 上安装 docker-compose的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

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

推荐答案

2021 年更新:docker-compose 已用 Go 重写,现在是 docker 命令 docker compose

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

因此,不再需要安装"它.
请参阅 docker compose.

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

2018 年 11 月 7 日更新:

Update 7th of november 2018:

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

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

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

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.

2017 年更新:现在通过 正式管理(适用于支持 Hyper-V 的 Windows 10)Windows 版 Docker".
请参阅安装适用于 Windows 的 Docker".
它确实有 chocolatey 安装 Docker 包,所以:

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 

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

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

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

For other Windows, you still need VirtualBox + Boot2Docker.

更新:docker compose 1.5(2015 年 11 月)应该使它正式适用于 Windows(自 RC2 起).

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

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

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

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

Original answer (Q1-Q3 2015).

警告:根据 docker-compose")似乎有一个错误rel="nofollow noreferrer">埃德莫利 (edmorley).

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

容器中的docker-compose"似乎存在缓存问题方法(参见 issue #6:对 docker-compose.yml 和 Dockerfile 的更改"未被检测到")

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

埃德推荐:

就目前而言,在 boot2docker 中运行 Python docker-compose 包似乎是 Windows 用户最可靠的解决方案(花了很多时间尝试与其他选择作斗争).

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

要从 PyPI 安装 docker-compose,请从 boot2docker 内部运行:

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

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

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

(su docker -c 是必需的,因为tce-load 不能作为root 运行,并且bootlocal.shroot 运行.bootlocal.shchmod 应该是不必要的一次 #915 已修复.
如果需要追加而不是覆盖 bootlocal.sh,请将 -a 添加到 tee 命令.)

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

如果您希望使用 docker-compose 的预发布版本,请将 pip install -U docker-compose 替换为 pip install -U docker-compose>=1.3.0rc1 或等价物.

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:

我还运行 docker-compose(在 Windows boot2docker 上)在图像中:

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

  • cloning https://github.com/docker/compose in /c/Users/<username>/myproject/compose (in order to have persistence, since /c/Users/<username> is automatically mounted, when I use VirtualBox with its extension pack )

构建 docker-compose 镜像:

building the docker-compose image:

  cd /c/Users/<username>/myproject/compose
  # that will put the repo in a detached HEAD, but it does not matter here
  git checkout 1.2.0
  docker build -t docker-compose .

  • 添加dc"别名(在 profile 文件,我启动 boot2docker ssh 会话.)

  • adding a 'dc' alias (in a profile file that I copy to my /home/docker/.ashrc before launching the boot2docker ssh session.)

      dc='docker run --rm -i -t -v /var/run/docker.sock:/var/run/docker.sock -v `pwd`:`pwd` -w `pwd` docker-compose'
    

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

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

    这篇关于如何在 Windows 上安装 docker-compose的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆