如何使用Docker-Py运行Docker标签



在命令行上,您可以运行docker tag [from] [to]以给图像另一个名称。该文档没有提供有关如何以编程方式执行此操作的任何信息。

您如何使用Docker-Py进行Docker标签操作?

它不在文档中,而是Image对象具有tag方法。

如果您运行

>>> dir(docker.from_env().images.get('my_image:latest'))
['__class__', '__delattr__', '__dict__', '__doc__', '__eq__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'attrs', 'client', 'collection', 'history', 'id', 'id_attribute', 'labels', 'reload', 'save', 'short_id', 'tag', 'tags']

奇怪的是有一个tag属性。

>>> docker.from_env().images.get('my_image:latest').tag
<bound method Image.tag of <Image: 'my_image:latest'>>

运行它会产生:

>>> docker.from_env().images.get('my_image:latest').tag('my_image:foobar')
True

在命令行上运行 docker images显示标签操作成功。

docker.from_env().images.get('my_image:latest').tag.__doc__
Tag this image into a repository. Similar to the ``docker tag``
        command.
        Args:
            repository (str): The repository to set for the tag
            tag (str): The tag name
            force (bool): Force
        Raises:
            :py:class:`docker.errors.APIError`
                If the server returns an error.
        Returns:
            (bool): ``True`` if successful

最新更新