在Linux系统上安装Docker Compose

本文根据 docker文档原文 Install Docker Compose进行翻译并加入自己的补充

Prerequisites先决条件

Docker Compose relies on Docker Engine for any meaningful work, so make sure you have Docker Engine installed either locally or remote, depending on your setup.

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

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

       在Mac和Windows的Docker桌面等桌面系统上,这些桌面安装中包含Docker Compose作为桌面安装的一部分。

  • On Linux systems, first install the Docker for your OS as described on the Get Docker page, then come back here for instructions on installing Compose on Linux systems.

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

  • To run Compose as a non-root user, see Manage Docker as a non-root user.

       以非root用户身份运行Compose,参考Manage Docker as a non-root user.

Install Compose安装Compose 

 Follow the instructions below to install Compose on Mac, Windows, Windows Server 2016, or Linux systems, or find out about alternatives like using the pip Python package manager or installing Compose as a container.

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

Install a different version

The instructions below outline installation of the current stable release (v1.24.1) of Compose. To install a different version of Compose, replace the given release number with the one that you want. Compose releases are also listed and available for direct download on the Compose repository release page on GitHub. To install a pre-release of Compose, refer to the install pre-release builds section.

Install Compose on Linux systems在linux系统上安装Compose

On Linux, you can download the Docker Compose binary from the Compose repository release page on GitHub. Follow the instructions from the link, which involve running the curl command in your terminal to download the binaries.

These step-by-step instructions are also included below.

这些分步说明也包含在下面。

For alpine, the following dependency packages are needed: py-pippython-devlibffi-devopenssl-devgcclibc-dev, and make.

对于alpine,需要以下依赖包:py-pip,python-dev,libffi-dev,openssl-dev,gcc,libc-dev和make。

  1. Run this command to download the current stable release of Docker Compose:运行此命令以下载Docker Compose的当前稳定版本

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

    To install a different version of Compose, substitute 1.24.1 with the version of Compose you want to use.

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

    If you have problems installing with curl, see Alternative Install Options tab above.

  2. Apply executable permissions to the binary:将可执行权限应用于二进制文件

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

Note: If the command docker-compose fails after installation, check your path. You can also create a symbolic link to /usr/bin or any other directory in your path.

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

For example:例子

sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
  1. Optionally, install command completion for the bash and zsh shell. 可选择项,为bash和shell安装命令命令补充完成

  2. Test the installation.测试安装

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

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 athttps://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.

Upgrading升级

If you’re upgrading from Compose 1.2 or earlier, remove or migrate your existing containers after upgrading Compose. This is because, as of version 1.3, Compose uses Docker labels to keep track of containers, and your containers need to be recreated to add the labels.

If Compose detects containers that were created without labels, it refuses to run, so that you don’t end up with two sets of them. If you want to keep using your existing containers (for example, because they have data volumes you want to preserve), you can use Compose 1.5.x to migrate them with the following command:

docker-compose migrate-to-labels

Alternatively, if you’re not worried about keeping them, you can remove them. Compose just creates new ones.

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

Uninstallation卸载

To uninstall Docker Compose if you installed using curl:卸载Docker Compose(如果您使用Curl安装):

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

To uninstall Docker Compose if you installed using pip:卸载Docker Compose(如果您使用pip安装):

pip uninstall docker-compose

Got a “Permission denied” error?

If you get a “Permission denied” error using either of the above methods, you probably do not have the proper permissions to remove docker-compose. To force the removal, prepend sudoto either of the above commands and run again.

 

uname命令说明:

在通过curl安装Compose的命令中,用到了uname,uname -s、uname -m

uname命令用于显示系统信息,可显示电脑以及操作系统的相关信息。

语法

uname [-amnrsv][--help][--version]

参数说明

-a或--all  显示全部的信息。
-m或--machine  显示电脑类型。
-n或-nodename  显示在网络上的主机名称。
-r或--release  显示操作系统的发行编号。
-s或--sysname  显示操作系统名称。
-v  显示操作系统的版本。
--help  显示帮助。
--version  显示版本信息。

如,在我们下载compose的命令中用到的,就是根据你的电脑信息下载相应的Compose

在github中我们可以找到docker-compose-Linux-x86_64这个

在Linux系统上安装Docker Compose_第1张图片

Install command completion 安装命令完成

  1. On a current Linux OS (in a non-minimal installation), bash completion should be available.

  2. Place the completion script in /etc/bash_completion.d/.

     sudo curl -L https://raw.githubusercontent.com/docker/compose/1.24.1/contrib/completion/bash/docker-compose -o /etc/bash_completion.d/docker-compose
    

Compose file format compatibility matrix   Compose文件格式兼容性列表

Compose file format

Compose文件格式

Docker Engine

Docker Engine版本

1 1.9.0+
2.0 1.10.0+
2.1 1.12.0+
2.2, 3.0, 3.1, 3.2 1.13.0+
2.3, 3.3, 3.4, 3.5 17.06.0+
2.4 17.12.0+
3.6 18.02.0+
3.7 18.06.0+

你可能感兴趣的:(docker)