一次docker-compose升级问题排查
更新:HHH   时间:2023-1-7


系统和docker信息

  • (1)执行cat /etc/redhat-release:

CentOS Linux release 7.5.1804 (Core)

  • (2)执行docker --version:

Docker version 17.09.0-ce, build afdb6d4

  • (3)执行docker-compose version:
docker-compose version 1.23.2, build 1110ad0
docker-py version: 3.7.0
CPython version: 2.7.5
OpenSSL version: OpenSSL 1.0.2k-fips  26 Jan 2017

事件原因

最近由于开发同学项目需求,需要将docker-compose版本从1.12.x升级至1.21.x(21版本以上,目前是1.23.2)~

操作过程

  • (1)升级pip并安装docker-compose:
pip install --upgrade pip

pip install docker-compose==1.23.2

出现如下报错:

Cannot uninstall 'texttable'. 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.

解决方法:

进入/usr/lib/python(你的版本号)/site-packages/目录,直接删包目录:

rm -rf texttable-*.egg-info

  • (2)再次pip安装docker-compose

pip install docker-compose==1.23.2

此时,我们使用docker-compose version命令是正常的,但是当我们进入docker-compose.yml文件路径,执行docker-compose up -ddocker-compose ps时,出现如下报错:

Traceback (most recent call last):
  File "/usr/bin/docker-compose", line 10, in <module>
    sys.exit(main())
  File "/usr/lib/python2.7/site-packages/compose/cli/main.py", line 71, in main
    command()
  File "/usr/lib/python2.7/site-packages/compose/cli/main.py", line 124, in perform_command
    project = project_from_options('.', options)

或者是这样的报错:

Traceback (most recent call last):
  File "/usr/bin/docker-compose", line 6, in <module>
    from compose.cli.main import main
  File "/usr/lib/python2.7/site-packages/compose/cli/main.py", line 22, in <module>
    from ..bundle import get_image_digests
  File "/usr/lib/python2.7/site-packages/compose/bundle.py", line 13, in <module>
    from .network import get_network_defs_for_service
  File "/usr/lib/python2.7/site-packages/compose/network.py", line 9, in <module>
    from docker.types import IPAMConfig
ImportError: cannot import name IPAMConfig

亦或者是这样的报错:

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
ImportError: No module named docker

最终的结果都是一样的,就是docker-compose无法使用~~

这里提供一个处理上面问题的方法

为了不碰到上面棘手的报错,正确升级姿势总结如下:

主要步骤如下:

  • (1)使用pip list|grep docker查看已安装相关docker包信息

  • (2)手动卸载第一步列出来的包,如下:

    <1> pip uninstall docker

    <2> pip uninstall docker-compose

    <3> pip uninstall docker-py

    <4> pip uninstall docker-pycreds

    <5> pip uninstall dockerpty

  • (3)安装docker-compose:pip install docker-compose==1.23.2 -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com#<== 这里使用豆瓣的源,比较快~

  • (4)如果第三步报错Cannot uninstall 'texttable',请执行上面提到的解决方法~,然后再次安装docker-compose即可。

参考文档

  • 删除distutils installed的内容
返回云计算教程...