Docker提供一个容器编排工具——Docker Compose,它允许用户在一个模版(YAML格式)中定义一组相关联的应用容器。这组容器会根据配置模版中的“–link”等参数。对启动的优先级自动排序,简单执行一条“docker-compose up”,就可以把同一个服务中的多个容器依次创建和启动。
方法一:
直接从github下载即可,前提要先安装Docker,版本要1.9.1以上
Note that Compose 1.8.0 requires Docker Engine 1.10.0 or later for version 2 of the Compose File format, and Docker Engine 1.9.1 or later for version 1.
curl -L https://github.com/docker/compose/releases/download/1.19.0-rc3/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
实际操作过程中,该请求地址返回404,安装失败。
也可以用pip或官网的run.sh脚本安装
方法二:
通过pip的方式安装。
centos安装pip命令如下:
# yum -y install epel-release
# yum install python-pip
# pip install --upgrade pip
ubuntu安装Pip命令如下:
$ sudo apt-get install python-pip python-dev build-essential
$ sudo pip install --upgrade pip
$ sudo pip install --upgrade virtualenv
pip安装完成后,安装compose:
pip install docker-compose
通过命令检查安装是否成功:
docker-compose
查看docker compose版本
docker-compose -v
ubuntu由于采用curl方式安装了docker 18.01.0-ce版本,采用上述方法直接安装docker compose一次性成功。
root@lei-VirtualBox:/# docker --version
Docker version 18.01.0-ce, build 03596f5
root@lei-VirtualBox:/#
root@lei-VirtualBox:/# docker-compose -v
docker-compose version 1.18.0, build 8dd22a9
centos安装的时候碰到了问题。使用yum安装默认安装1.12.0版本docker,采用以上pip方式安装docker compose时,运行docker-compose报错:
[root@localhost ~]# docker-compose
Traceback (most recent call last):
File "/usr/bin/docker-compose", line 7, in <module>
from compose.cli.main import main
File "/usr/lib/python2.7/site-packages/compose/cli/main.py", line 17, in <module>
import docker
File "/usr/lib/python2.7/site-packages/docker/__init__.py", line 2, in <module>
from .api import APIClient
File "/usr/lib/python2.7/site-packages/docker/api/__init__.py", line 2, in <module>
from .client import APIClient
File "/usr/lib/python2.7/site-packages/docker/api/client.py", line 9, in <module>
import websocket
File "/usr/lib/python2.7/site-packages/websocket/__init__.py", line 23, in <module>
from ._app import WebSocketApp
File "/usr/lib/python2.7/site-packages/websocket/_app.py", line 35, in <module>
from ._core import WebSocket, getdefaulttimeout
File "/usr/lib/python2.7/site-packages/websocket/_core.py", line 33, in <module>
from ._handshake import *
File "/usr/lib/python2.7/site-packages/websocket/_handshake.py", line 30, in <module>
from ._http import *
File "/usr/lib/python2.7/site-packages/websocket/_http.py", line 33, in <module>
from ._url import *
File "/usr/lib/python2.7/site-packages/websocket/_url.py", line 27, in <module>
from six.moves.urllib.parse import urlparse
ImportError: No module named urllib.parse
此时的解决方法如下(不理解原因):
pip install docker_pycreds
再次查看compose版本,问题修复。
[root@localhost ~]# docker -v
Docker version 1.12.6, build 3e8e77d/1.12.6
[root@localhost ~]# docker-compose -v
docker-compose version 1.19.0, build 9e633ef