最新消息: 新版网站上线了!!!

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

dockerÌṩÁËPython¡¢GoµÈ±à³ÌÓïÑÔµÄapi¡£×î½ü´òËãÓÃdocker SDK for Python£¨ÒÔϼò³Ædocker-py£©×öµã¶«Î÷£¬±¾À´ÒÔΪ°´ÕÕ¹ÙÍøÉϵIJ½Öè°²×°ºÜ¼òµ¥£¬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') Ëƺõ¾ÍÄܱÜÃâ°æ±¾²»¼æÈݵÄÎÊÌâÁË¡£È»¶ø»¹ÊDZ¨´í£º

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°æ±¾²»¼æÈݵÄÎÊÌâ¾ÍÊÇС±à·ÖÏí¸ø´ó¼ÒµÄÈ«²¿ÄÚÈÝÁË£¬Ï£ÍûÄܸø´ó¼ÒÒ»¸ö²Î¿¼£¬Ò²Ï£Íû´ó¼Ò¶à¶àÖ§³Ö½Å±¾Ö®¼Ò¡£

转载请注明:谷谷点程序 » 快速解决docker-py api版本不兼容的问题