安装Docker Compose

165次阅读
没有评论

您可以在macOS,Windows和64位Linux上运行Compose。

前提条件🔗

Docker Compose依靠Docker Engine进行任何有意义的工作,因此请确保根据您的设置在本地或远程安装Docker Engine。

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

  • 在Linux系统上,首先 按照“获取Docker”页面上的说明为您的操作系统安装 Docker Engine,然后返回此处以获取有关在Linux系统上安装Compose的说明。

  • 要以非root用户身份运行Compose,请参阅以非root用户身份管理Docker

安装撰写ose

请按照以下说明在Mac,Windows,Windows Server 2016或Linux系统上安装Compose,或查找其他替代方法,例如使用pip Python软件包管理器或将Compose作为容器安装。

安装其他版本

以下说明概述了Compose当前稳定版本(v1.28.4)的安装。要安装其他版本的Compose,请使用所需的版本号替换给定的发行号。还列出了Compose版本,可以在GitHub上的Compose存储库版本页面上直接下载 。要安装Compose的预发布版本,请参阅“安装预发布内部版本” 部分。

  • 苹果电脑
  • 视窗
  • Windows服务器
  • 的Linux
  • 备用安装选项
  • 发行前版本

在macOS上安装Compose🔗

Docker Desktop for Mac包括Compose以及其他Docker应用程序,因此Mac用户不需要单独安装Compose。有关安装说明,请参阅在Mac上安装Docker Desktop

在Windows桌面系统上安装Compose🔗

Docker Desktop for Windows includes Compose along with other Docker apps, so most Windows users do not need to install Compose separately. For install instructions, see Install Docker Desktop on Windows.

If you are running the Docker daemon and client directly on Microsoft Windows Server, follow the instructions in the Windows Server tab.

Install Compose on Windows Server🔗

Follow these instructions if you are running the Docker daemon and client directly on Microsoft Windows Server and want to install Docker Compose.

  1. Start an “elevated” PowerShell (run it as administrator). Search for PowerShell, right-click, and choose Run as administrator. When asked if you want to allow this app to make changes to your device, click Yes.

  2. In PowerShell, since GitHub now requires TLS1.2, run the following:

    
    

    Then run the following command to download the current stable release of Compose (v1.28.4):

    Invoke-WebRequest "https://github.com/docker/compose/releases/download/1.28.4/docker-compose-Windows-x86_64.exe" -UseBasicParsing -OutFile $Env:ProgramFiles\Docker\docker-compose.exe

Note: On Windows Server 2019, you can add the Compose executable to $Env:ProgramFiles\Docker. Because this directory is registered in the system PATH, you can run the docker-compose --version command on the subsequent step with no additional configuration.

> To install a different version of Compose, substitute `1.28.4`
> with the version of Compose you want to use.
  1. Test the installation.

    docker-compose --version
    
    docker-compose version 1.28.4, build 01110ad01

在Linux系统上安装Compose🔗

在Linux上,您可以从GitHub上Compose存储库发行页面下载Docker Compose二进制文件 。按照链接中的说明进行操作,其中包括curl在终端中运行命令以下载二进制文件。这些分步说明也包含在下面。

对于alpine,需要以下依赖包: py-pippython3-devlibffi-devopenssl-devgcclibc-devrustcargomake

  1. 运行以下命令以下载Docker Compose的当前稳定版本:

    sudo curl -L "https://github.com/docker/compose/releases/download/1.28.4/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

    要安装其他版本的Compose,请替换1.28.4 为要使用的Compose版本。

    如果使用进行安装时遇到问题curl,请参见 上方的“备用安装选项”标签。

  2. 将可执行权限应用于二进制文件:

    sudo chmod +x /usr/local/bin/docker-compose

注意:如果命令docker-compose在安装后失败,请检查您的路径。您也可以创建指向/usr/bin或路径中任何其他目录的符号链接。

例如:

sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
  1. (可选)为 和shell安装命令完成bashzsh

  2. 测试安装。

    $ docker-compose --version
    docker-compose version 1.28.4, build 1110ad01

Alternative install options🔗

Install using pip

For alpine, the following dependency packages are needed: py-pip, python3-dev, libffi-dev, openssl-dev, gcc, libc-dev, rust, cargo, and make.

Compose can be installed from pypi using pip. If you install using pip, we recommend that you use a virtualenv because many operating systems have python system packages that conflict with docker-compose dependencies. See the virtualenv tutorial to get started.

pip install docker-compose

If you are not using virtualenv,

sudo pip install docker-compose

pip version 6.0 or greater is required.

Install as a container

Compose can also be run inside a container, from a small bash script wrapper. To install compose as a container run this command:

sudo curl -L --fail https://github.com/docker/compose/releases/download/1.28.4/run.sh -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose

Install pre-release builds🔗

If you’re interested in trying out a pre-release build, you can download release candidates from the Compose repository release page on GitHub. Follow the instructions from the link, which involves running the curl command in your terminal to download the binaries.

Pre-releases built from the “master” branch are also available for download at https://dl.bintray.com/docker-compose/master/.

Pre-release builds allow you to try out new features before they are released, but may be less stable.


升级🔗

如果要从Compose 1.2或更早版本进行升级,请在升级Compose之后删除或迁移现有容器。这是因为从1.3版开始,Compose使用Docker标签来跟踪容器,并且需要重新创建容器以添加标签。

如果Compose检测到创建的没有标签的容器,它将拒绝运行,这样您就不会最终获得两组标签。如果要继续使用现有容器(例如,因为它们具有要保留的数据量),则可以使用Compose 1.5.x通过以下命令迁移它们:

docker-compose migrate-to-labels

另外,如果您不担心保留它们,可以将其删除。撰写只是创建新的。

docker container rm -f -v myapp_web_1 myapp_db_1 ...

卸载🔗

如果使用curl以下命令安装,则要卸载Docker Compose :

sudo rm /usr/local/bin/docker-compose

如果使用pip以下命令安装,则要卸载Docker Compose :

pip uninstall docker-compose