欢迎来到代码驿站!

Python代码

当前位置:首页 > 软件编程 > Python代码

快速解决docker-py api版本不兼容的问题

时间:2021-03-15 09:50:58|栏目:Python代码|点击:

docker提供了Python、Go等编程语言的api。最近打算用docker SDK for Python(以下简称docker-py)做点东西,本来以为按照官网上的步骤安装很简单,pip install docker 就行,然而出现了版本不兼容的问题。

报错如下:

docker.errors.APIError: 400 Client Error: Bad Request ("client is newer than server (client API version: 1.30, server API version: 1.19)")

可以使用指令 docker version查看版本号,果然api版本是1.19,但是docker-py的版本是1.30。在docker-py官网 里找一找解决方法,from_env()的解释如下:

 from_env()

 Return a client configured from environment variables.

 The environment variables used are the same as those used by the Docker command-line client. They are:

 DOCKER_HOST

  The URL to the Docker host.

 DOCKER_TLS_VERIFY

  Verify the host against a CA certificate.

 DOCKER_CERT_PATH

  A path to a directory containing TLS certificates to use when connecting to the Docker host.

 Parameters: 

  version (str) ?C The version of the API to use. Set to auto to automatically detect the server's version. Default: 1.26
  timeout (int) ?C Default timeout for API calls, in seconds.
  ssl_version (int) ?C A valid SSL version.
  assert_hostname (bool) ?C Verify the hostname of the server.
  environment (dict) ?C The environment to read environment variables from. Default: the value of os.environ

有一个参数可以指定version,于是这样写:client=docker.from_env(version='1.19') 似乎就能避免版本不兼容的问题了。然而还是报错:

ValueError: zero length field name in format

搜了一下这是因为我的python版本是2.6,在对参数解析时出现格式问题,没办法,只好升级python2.7了。

在官网的change日志中可以看到,2.0版本之后就不再支持python2.6了。

2.0.0
...
Breaking changes
 Dropped support for Python 2.6

将python2.6升级到2.7,不仅要编译安装python2.7,还要把/usr/local/bin/pip2.7软连接给/usr/bin/pip 以覆盖原来的pip2.6,然后重新pip install docker

如果是centos系统,不要忘了修改/usr/bin/yum ,将第一行#!/usr/bin/python 改为#!/usr/bin/python2.6 ,否则yum指令无法使用。

上一篇:wxpython多线程防假死与线程间传递消息实例详解

栏    目:Python代码

下一篇:python3 通过 pybind11 使用Eigen加速代码的步骤详解

本文标题:快速解决docker-py api版本不兼容的问题

本文地址:http://www.codeinn.net/misctech/81113.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有