Docker学习之安装docker-compose命令(采用Python-pip命令安装)

本机系统环境介绍

Ubuntu系统环境介绍介绍
Ubuntu版本:18.04.1
系统配置: 64位
Linux内核:5.3.0-42-generic
Docker版本: 19.03.8

Docker Compose简介

Docker Compose:允许用户通过一个单独的docker-compose.yml来定义一组相关联的应用容器,也就是可以定义和运行多个Docker容器,负责实现对Docker容器集群的快速编排
Docker Compose有两个重要的概念
服务(Service):一个应用容器,实际上可以包含若干运行相同镜像的容器实例
项目(Porject):有一组关联的应用容器组成的一个完整的业务单元,在docker-compose.yml重定义,比如定义redis集群
重点:docker compose的默认管理对象是项目,通过子命令对项目中的一组容器进行便捷的生命周期管理
备注:Compose 支持 Linux、macOS、Windows 10 三大平台。

使用Python-pip命令进行安装

第一步:环境检查

## 查看是否安装过Python-pip
acestang@acestang:~$ sudo pip -V
sudo: pip:找不到命令
## 先查看是否安装过docker-compose如果安装过,先卸载
acestang@acestang:~$ sudo docker-compose version
sudo: docker-compose:找不到命令

第二步:安装Python-pip

# 在CentOS中需要先安装 epel-release 主要是这个软件包会自动配置yum的软件仓库,我们是Ubuntu系统所以不需要,直接安装python-pip
acestang@acestang:~$ sudo apt-get install -y python-pip
# 测试是否安装成功
acestang@acestang:~$ sudo pip -V
# 显示出pip的版本号,说明安装成功
pip 9.0.1 from /usr/lib/python2.7/dist-packages (python 2.7)

第三步:安装docker-compose

acestang@acestang:~$sudo pip install docker-compose
Collecting docker-compose
  Downloading https://files.pythonhosted.org/packages/ec/35/1dfbb8e6b2ce5d290622a49cae0a7f3cf09cdc4341380a600aee00530881/docker_compose-1.25.5-py2.py3-none-any.whl (139kB)
    100% |████████████████████████████████| 143kB 2.0kB/s 
Collecting docopt<1,>=0.6.1 (from docker-compose)
  Downloading https://files.pythonhosted.org/packages/a2/55/8f8cab2afd404cf578136ef2cc5dfb50baa1761b68c9da1fb1e4eed343c9/docopt-0.6.2.tar.gz
Collecting six<2,>=1.3.0 (from docker-compose)
  Downloading https://files.pythonhosted.org/packages/65/eb/1f97cb97bfc2390a276969c6fae16075da282f5058082d4cb10c6c5c1dba/six-1.14.0-py2.py3-none-any.whl
Collecting backports.ssl-match-hostname<4,>=3.5; python_version < "3.5" (from docker-compose)
  Downloading https://files.pythonhosted.org/packages/ff/2b/8265224812912bc5b7a607c44bf7b027554e1b9775e9ee0de8032e3de4b2/backports.ssl_match_hostname-3.7.0.1.tar.gz
Collecting PyYAML<6,>=3.10 (from docker-compose)
  Downloading https://files.pythonhosted.org/packages/64/c2/b80047c7ac2478f9501676c988a5411ed5572f35d1beff9cae07d321512c/PyYAML-5.3.1.tar.gz (269kB)
    72% |███████████████████████▏        | 194kB 3.3kB/s eta 0:00:23Exception:
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "/usr/lib/python2.7/dist-packages/pip/commands/install.py", line 353, in run
    wb.build(autobuilding=True)
  File "/usr/lib/python2.7/dist-packages/pip/wheel.py", line 749, in build
    self.requirement_set.prepare_files(self.finder)
  File "/usr/lib/python2.7/dist-packages/pip/req/req_set.py", line 380, in prepare_files
    ignore_dependencies=self.ignore_dependencies))
  File "/usr/lib/python2.7/dist-packages/pip/req/req_set.py", line 620, in _prepare_file
    session=self.session, hashes=hashes)
  File "/usr/lib/python2.7/dist-packages/pip/download.py", line 821, in unpack_url
# 悲催啊,安装到这里突然出错,可以看到

分析产生上述问题的原因

分析上面的问题,可能是默认安装python-compose使用的是python3而系统环境是Python2,所以安装失败
解决思路:把系统的默认Python2.7 升级到Python3
升级方法参考:链接: Linux常用命令(3)升级系统默认python2.7到python3最新版本.
升级后会出现pip命令不能使用的问题
解决pip命令不能使用参考:链接: Linux常用命令(4)解决升级系统默认python2.7到python3最新版本后pip命令不能使用的问题.

继续安装

acestang@acestang:~$ sudo pip install docker-compose
The directory '/home/acestang/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/acestang/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting docker-compose
  Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='pypi.python.org', port=443): Read timed out. (read timeout=15)",)': /simple/docker-compose/
  Downloading https://files.pythonhosted.org/packages/ec/35/1dfbb8e6b2ce5d290622a49cae0a7f3cf09cdc4341380a600aee00530881/docker_compose-1.25.5-py2.py3-none-any.whl (139kB)
    100% |████████████████████████████████| 143kB 9.2kB/s 
Requirement already satisfied: six<2,>=1.3.0 in /usr/lib/python3/dist-packages (from docker-compose)
Collecting docopt<1,>=0.6.1 (from docker-compose)
  Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', ConnectionResetError(104, '连接被对方重设'))': /simple/docopt/
  Could not find a version that satisfies the requirement docopt<1,>=0.6.1 (from docker-compose) (from versions: )
No matching distribution found for docopt<1,>=0.6.1 (from docker-compose)
# 又悲催了,安装又失败

分析产生上述问题的原因

问题展示:
分析问题:这个问题是在安装软件过程中,链接国外的镜像源导致下载失败
解决这个问题可以参考链接: Linux常用命令(4)解决升级系统默认python2.7到python3最新版本后pip命令不能使用的问题.

解决问题继续安装

acestang@acestang:~$ sudo pip install -U docker-compose
The directory '/home/acestang/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/acestang/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting docker-compose
  Url '#/docker-compose/' is ignored. It is either a non-existing path or lacks a specific scheme.
  .......
Installing collected packages: docker-compose
Successfully installed docker-compose-1.25.5
# 终于安装过程没有报错,进行下一步

第四步:检查是否安装成功

# 安装成功
acestang@acestang:~$ docker-compose --version
docker-compose version 1.25.5, build unknown

第五步:通过pip命令卸载docker-compose

acestang@acestang:~$ pip install docker-compose

小记

小记:虽然安装过程很艰辛,但是遇到问题不要慌,分析问题,找到问题的原因,总能够解决的.如果你在安装过程中遇到了问题,直接给我留言,大家一起分析问题解决!

原创文章 25 获赞 0 访问量 1805

猜你喜欢

转载自blog.csdn.net/ttf0203/article/details/105759427
今日推荐