一、按照官方文档推荐的安装方式
(1)下载docker-compose
执行如下命令进行下载
curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
若速度较慢,可以使用如下命令:
curl -L "https://mirror.ghproxy.com/https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
(2)修改目录权限
chmod +x /usr/local/bin/docker-compose
(3)创建软连接
ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
(4)验证安装是否完成
执行如下命令,如果可以正常显示版本号,则表示已经完成
docker-compose --version
二、使用pip install 的方式安装
因为docker-compose是使用python开发的,因此可以通过pip install 的方式安装
(1)首先需要确保pip已经安装完成,如下
如下,表示pip为基于python3.9的版本,这里最好安装基于python3.6以上的pip
[root@iZbp1flzt6x7pxmxfhmxeeZ ~]# pip3 --version
pip 21.2.4 from /usr/local/python3/lib/python3.9/site-packages/pip (python 3.9)
[root@iZbp1flzt6x7pxmxfhmxeeZ ~]#
(2)升级pip的版本
python3 -m pip install --upgrade pip
如:
[root@iZbp1flzt6x7pxmxfhmxeeZ ~]# python3 -m pip install --upgrade pip
Looking in indexes: http://mirrors.cloud.aliyuncs.com/pypi/simple/
Requirement already satisfied: pip in /usr/local/python3/lib/python3.9/site-packages (21.2.4)
Collecting pip
Downloading http://mirrors.cloud.aliyuncs.com/pypi/packages/a4/6d/6463d49a933f547439d6b5b98b46af8742cc03ae83543e4d7688c2420f8b/pip-21.3.1-py3-none-any.whl (1.7 MB)
|████████████████████████████████| 1.7 MB 105 kB/s
Installing collected packages: pip
Attempting uninstall: pip
Found existing installation: pip 21.2.4
Uninstalling pip-21.2.4:
Successfully uninstalled pip-21.2.4
WARNING: The scripts pip, pip3 and pip3.9 are installed in '/usr/local/python3/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed pip-21.3.1
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
[root@iZbp1flzt6x7pxmxfhmxeeZ ~]#
(3)安装docker-compose
pip3 install docker-compose
如下:
[root@iZbp1flzt6x7pxmxfhmxeeZ ~]# pip3 install docker-compose
Looking in indexes: http://mirrors.cloud.aliyuncs.com/pypi/simple/
Requirement already satisfied: docker-compose in /usr/local/python3/lib/python3.9/site-packages (1.29.2)
Requirement already satisfied: docker[ssh]>=5 in /usr/local/python3/lib/python3.9/site-packages (from docker-compose) (5.0.3)
Requirement already satisfied: PyYAML<6,>=3.10 in /usr/local/python3/lib/python3.9/site-packages (from docker-compose) (5.4.1)
Requirement already satisfied: jsonschema<4,>=2.5.1 in /usr/local/python3/lib/python3.9/site-packages (from docker-compose) (3.2.0)
Requirement already satisfied: python-dotenv<1,>=0.13.0 in /usr/local/python3/lib/python3.9/site-packages (from docker-compose) (0.19.1)
Requirement already satisfied: texttable<2,>=0.9.0 in /usr/local/python3/lib/python3.9/site-packages (from docker-compose) (1.6.4)
Requirement already satisfied: websocket-client<1,>=0.32.0 in /usr/local/python3/lib/python3.9/site-packages (from docker-compose) (0.59.0)
Requirement already satisfied: distro<2,>=1.5.0 in /usr/local/python3/lib/python3.9/site-packages (from docker-compose) (1.6.0)
Requirement already satisfied: docopt<1,>=0.6.1 in /usr/local/python3/lib/python3.9/site-packages (from docker-compose) (0.6.2)
Requirement already satisfied: dockerpty<1,>=0.4.1 in /usr/local/python3/lib/python3.9/site-packages (from docker-compose) (0.4.1)
Requirement already satisfied: requests<3,>=2.20.0 in /usr/local/python3/lib/python3.9/site-packages (from docker-compose) (2.26.0)
Requirement already satisfied: paramiko>=2.4.2 in /usr/local/python3/lib/python3.9/site-packages (from docker[ssh]>=5->docker-compose) (2.8.0)
Requirement already satisfied: six>=1.3.0 in /usr/local/python3/lib/python3.9/site-packages (from dockerpty<1,>=0.4.1->docker-compose) (1.16.0)
Requirement already satisfied: attrs>=17.4.0 in /usr/local/python3/lib/python3.9/site-packages (from jsonschema<4,>=2.5.1->docker-compose) (21.2.0)
Requirement already satisfied: pyrsistent>=0.14.0 in /usr/local/python3/lib/python3.9/site-packages (from jsonschema<4,>=2.5.1->docker-compose) (0.18.0)
Requirement already satisfied: setuptools in /usr/local/python3/lib/python3.9/site-packages (from jsonschema<4,>=2.5.1->docker-compose) (57.4.0)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in /usr/local/python3/lib/python3.9/site-packages (from requests<3,>=2.20.0->docker-compose) (1.26.6)
Requirement already satisfied: charset-normalizer~=2.0.0 in /usr/local/python3/lib/python3.9/site-packages (from requests<3,>=2.20.0->docker-compose) (2.0.7)
Requirement already satisfied: idna<4,>=2.5 in /usr/local/python3/lib/python3.9/site-packages (from requests<3,>=2.20.0->docker-compose) (3.3)
Requirement already satisfied: certifi>=2017.4.17 in /usr/local/python3/lib/python3.9/site-packages (from requests<3,>=2.20.0->docker-compose) (2021.5.30)
Requirement already satisfied: cryptography>=2.5 in /usr/local/python3/lib/python3.9/site-packages (from paramiko>=2.4.2->docker[ssh]>=5->docker-compose) (35.0.0)
Requirement already satisfied: pynacl>=1.0.1 in /usr/local/python3/lib/python3.9/site-packages (from paramiko>=2.4.2->docker[ssh]>=5->docker-compose) (1.4.0)
Requirement already satisfied: bcrypt>=3.1.3 in /usr/local/python3/lib/python3.9/site-packages (from paramiko>=2.4.2->docker[ssh]>=5->docker-compose) (3.2.0)
Requirement already satisfied: cffi>=1.1 in /usr/local/python3/lib/python3.9/site-packages (from bcrypt>=3.1.3->paramiko>=2.4.2->docker[ssh]>=5->docker-compose) (1.15.0)
Requirement already satisfied: pycparser in /usr/local/python3/lib/python3.9/site-packages (from cffi>=1.1->bcrypt>=3.1.3->paramiko>=2.4.2->docker[ssh]>=5->docker-compose) (2.20)
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
[root@iZbp1flzt6x7pxmxfhmxeeZ ~]#
(4)验证是否安装完成
docker-compose -version
如下
[root@iZbp1flzt6x7pxmxfhmxeeZ ~]# docker-compose -version
docker-compose version 1.29.2, build unknown
[root@iZbp1flzt6x7pxmxfhmxeeZ ~]#