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遇到這種情況方法也通用,搜索<package name>.egg-info,找到後刪除即可
[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]#