docker py和build and push AttributeError:' Image'对象没有属性' push'

时间:2018-06-17 13:22:35

标签: docker

如何使用docker py构建并推送到服务器?

    docker_path = "/path/to/dockerfile/puredocker"
    build_image = docker_client.images.build(path=docker_path,tag=tag)
    image = build_image[0]
    print ('build_image:',build_image)

    for line in image.push(registry_name, stream=True):
        print (line)

我的形象不是吗?

build_image: (<Image: 'testme:latest'>, <itertools._tee object at 0x10d9d0ec8>)

因此:image = build_image [0]

for line in image.push(registry_name, stream=True):
     AttributeError: 'Image' object has no attribute 'push'

1 个答案:

答案 0 :(得分:1)

我认为你应该使用get方法。

   docker_path = "/path/to/dockerfile/puredocker"
   client.images.build(path=docker_path, tag=tagged)
   image = client.images.get(<the name of the image>)
   print(image.short_id)
   client.images.push('registry/registry', tag=tagged)

https://docker-py.readthedocs.io/en/stable/images.html?highlight=push#docker.models.images.ImageCollection.get