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


Posted in Python onAugust 30, 2019

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) ? The version of the API to use. Set to auto to automatically detect the server's version. Default: 1.26
  timeout (int) ? Default timeout for API calls, in seconds.
  ssl_version (int) ? A valid SSL version.
  assert_hostname (bool) ? Verify the hostname of the server.
  environment (dict) ? 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指令无法使用。

以上这篇快速解决docker-py api版本不兼容的问题就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持三水点靠木。

Python 相关文章推荐
Python模块WSGI使用详解
Feb 02 Python
使用urllib库的urlretrieve()方法下载网络文件到本地的方法
Dec 19 Python
Python 使用list和tuple+条件判断详解
Jul 30 Python
python用quad、dblquad实现一维二维积分的实例详解
Nov 20 Python
python实现while循环打印星星的四种形状
Nov 23 Python
python 实现屏幕录制示例
Dec 23 Python
python如何使用Redis构建分布式锁
Jan 16 Python
自学python用什么系统好
Jun 23 Python
Python趣味入门教程之循环语句while
Aug 26 Python
Python Pandas list列表数据列拆分成多行的方法实现
Dec 14 Python
Python图像处理之图像拼接
Apr 28 Python
总结几个非常实用的Python库
Jun 26 Python
Python 使用 Pillow 模块给图片添加文字水印的方法
Aug 30 #Python
python pillow模块使用方法详解
Aug 30 #Python
docker-py 用Python调用Docker接口的方法
Aug 30 #Python
tesserocr与pytesseract模块的使用方法解析
Aug 30 #Python
Django获取应用下的所有models的例子
Aug 30 #Python
Django自带日志 settings.py文件配置方法
Aug 30 #Python
tensorflow如何批量读取图片
Aug 29 #Python
You might like
PHP调用Twitter的RSS的实现代码
2010/03/10 PHP
[原创]ThinkPHP中SHOW_RUN_TIME不能正常显示运行时间的解决方法
2015/10/10 PHP
thinkphp关于简单的权限判定方法
2017/04/03 PHP
PHP编程实现微信企业向用户付款的方法示例
2017/07/26 PHP
laravel框架中控制器的创建和使用方法分析
2019/11/23 PHP
jscript之Read an Excel Spreadsheet
2007/06/13 Javascript
JQuery 确定css方框模型(盒模型Box Model)
2010/01/22 Javascript
Javascript 类与静态类的实现
2010/04/01 Javascript
jQuery登陆判断简单实现代码
2013/04/21 Javascript
利用jQuery实现可输入搜索文字的下拉框
2013/10/23 Javascript
jQuery切换所有复选框选中状态的方法
2015/07/02 Javascript
js如何准确获取当前页面url网址信息
2020/09/13 Javascript
JavaScript通过HTML的class来获取HTML元素的方法总结
2016/05/24 Javascript
js判断是否是手机页面
2017/03/17 Javascript
Vue创建头部组件示例代码详解
2018/10/23 Javascript
node使用request请求的方法
2019/12/20 Javascript
JS代码检查工具ESLint介绍与使用方法
2020/02/04 Javascript
JavaScript实现多球运动效果
2020/09/07 Javascript
Vue自定义多选组件使用详解
2020/09/08 Javascript
jQuery实现移动端扭蛋机抽奖
2020/11/08 jQuery
python求列表交集的方法汇总
2014/11/10 Python
Python使用minidom读写xml的方法
2015/06/03 Python
python3实现暴力穷举博客园密码
2016/06/19 Python
Python3从零开始搭建一个语音对话机器人的实现
2019/08/23 Python
python线程安全及多进程多线程实现方法详解
2019/09/27 Python
python 实现字符串下标的输出功能
2020/02/13 Python
Python如何设置指定窗口为前台活动窗口
2020/08/12 Python
Cpython解释器中的GIL全局解释器锁
2020/11/09 Python
美国知名的隐形眼镜电商:Contacts America
2019/11/19 全球购物
Servlet面试题库
2015/07/18 面试题
函授本科自我鉴定
2014/02/04 职场文书
公司承诺书怎么写
2014/05/24 职场文书
优秀研究生主要事迹
2014/06/03 职场文书
班子四风对照检查材料
2014/08/21 职场文书
PHP策略模式写法
2021/04/01 PHP
Go语言 go程释放操作(退出/销毁)
2021/04/30 Golang