mirror of https://github.com/docker/docker-py.git
model: add remove() to Image (#3026)
Allow an Image to be deleted by calling the remove() method on it, just like a Volume. Signed-off-by: Ahmon Dancy <dancy@dancysoft.com> Signed-off-by: Milas Bowman <milas.bowman@docker.com> Co-authored-by: Ahmon Dancy <dancy@dancysoft.com>
This commit is contained in:
parent
26753c81de
commit
868e996269
|
|
@ -61,6 +61,24 @@ class Image(Model):
|
||||||
"""
|
"""
|
||||||
return self.client.api.history(self.id)
|
return self.client.api.history(self.id)
|
||||||
|
|
||||||
|
def remove(self, force=False, noprune=False):
|
||||||
|
"""
|
||||||
|
Remove this image.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
force (bool): Force removal of the image
|
||||||
|
noprune (bool): Do not delete untagged parents
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
:py:class:`docker.errors.APIError`
|
||||||
|
If the server returns an error.
|
||||||
|
"""
|
||||||
|
return self.client.api.remove_image(
|
||||||
|
self.id,
|
||||||
|
force=force,
|
||||||
|
noprune=noprune,
|
||||||
|
)
|
||||||
|
|
||||||
def save(self, chunk_size=DEFAULT_DATA_CHUNK_SIZE, named=False):
|
def save(self, chunk_size=DEFAULT_DATA_CHUNK_SIZE, named=False):
|
||||||
"""
|
"""
|
||||||
Get a tarball of an image. Similar to the ``docker save`` command.
|
Get a tarball of an image. Similar to the ``docker save`` command.
|
||||||
|
|
|
||||||
|
|
@ -150,6 +150,16 @@ class ImageTest(unittest.TestCase):
|
||||||
image.history()
|
image.history()
|
||||||
client.api.history.assert_called_with(FAKE_IMAGE_ID)
|
client.api.history.assert_called_with(FAKE_IMAGE_ID)
|
||||||
|
|
||||||
|
def test_remove(self):
|
||||||
|
client = make_fake_client()
|
||||||
|
image = client.images.get(FAKE_IMAGE_ID)
|
||||||
|
image.remove()
|
||||||
|
client.api.remove_image.assert_called_with(
|
||||||
|
FAKE_IMAGE_ID,
|
||||||
|
force=False,
|
||||||
|
noprune=False,
|
||||||
|
)
|
||||||
|
|
||||||
def test_save(self):
|
def test_save(self):
|
||||||
client = make_fake_client()
|
client = make_fake_client()
|
||||||
image = client.images.get(FAKE_IMAGE_ID)
|
image = client.images.get(FAKE_IMAGE_ID)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue