1,官网提供的方法(稳定,不需要想太多,就是下载时间太久,小时为单位)
对应官网连接https://docs.docker.com/compose/install/
先下载对应的二进制代码
sudo curl -L "https://github.com/docker/compose/releases/download/1.25.5/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
将可执行权限应用于二进制文件
sudo chmod +x /usr/local/bin/docker-compose
然后就好了docker-compose -v查看版本
2,pip安装-优点速度快,但各种bug成出不穷,踩无数坑
这个是我目前系统环境的版本,只有下面内核版本一致可以一波带走安装完成docker-compose(其他版本我不敢保证)
[root@iZwz90exx7s8zzkhj49a2qZ docker]# cat /etc/redhat-release
CentOS Linux release 7.7.1908 (Core)
[root@iZwz90exx7s8zzkhj49a2qZ docker]# python -V
Python 2.7.5
[root@iZwz90exx7s8zzkhj49a2qZ docker]# pip -V
pip 20.0.2 from /usr/lib/python2.7/site-packages/pip (python 2.7)
[root@iZwz90exx7s8zzkhj49a2qZ docker]#
首先检查 Linux 有没有安装 python-pip 包:yum install python-pip。
没有 python-pip 包就执行:yum install epel-release -y 命令。
执行成功之后,再次执行:yum install python -y。
对安装好的 pip 进行升级:pip install --upgrade pip。
升级完 pip 工具之后,使用:pip install docker-compose 安装 docker-compose。
这个时在安装docker-compose时的报错,个人发现下报这个错的时候如果不去安装gcc的话时无法修复这个问题的,会反复出现,所以先用下面命令搞定gcc,在解决下面报错
yum -y install gcc
yum -y install gcc-c++
Running setup.py install for subprocess32 ... error
ERROR: Command errored out with exit status 1:
command: /usr/bin/python2 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-FjQOUA/subprocess32/setup.py'"'"'; __file__='"'"'/tmp/pip-install-FjQOUA/subprocess32/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-eoCZzb/install-record.txt --single-version-externally-managed --compile --install-headers /usr/include/python2.7/subprocess32
cwd: /tmp/pip-install-FjQOUA/subprocess32/
Complete output (51 lines):
/usr/lib64/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'python_requires'
warnings.warn(msg)
running install
running build
running build_py
creating build
creating build/lib.linux-x86_64-2.7
copying subprocess32.py -> build/lib.linux-x86_64-2.7
running build_ext
running build_configure
checking for gcc... no
checking for cc... no
checking for cl.exe... no
configure: error: in `/tmp/pip-install-FjQOUA/subprocess
yum -y install python-devel python-subprocess32
在次安装docker-compose
ERROR: Cannot uninstall 'subprocess32'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.
找到subprocess32.egg-info,一般就在usr/lib/python2.7或者其他安装pythonxxx dist-packages等路径里,可以直接在/目录下全局搜索。然后删掉即可.
其他的package遇到这种情况方法也通用,搜索
[root@node01 pinpoint-docker]# find / -name *subpro*.egg-info
/usr/lib64/python2.7/site-packages/subprocess32-3.2.6-py2.7.egg-info
[root@node01 pinpoint-docker]# rm -f /usr/lib64/python2.7/site-packages/subprocess32-3.2.6-py2.7.egg-info [root@node01 pinpoint-docker]# pip install docker-compose
... ...
# 终于好了
[root@node01 pinpoint-docker]# docker-compose -v
docker-compose version 1.25.5, build unknown
[root@node01 pinpoint-docker]#