From 868e996269b6934420f0cd2104621b6f45f668e5 Mon Sep 17 00:00:00 2001 From: Milas Bowman Date: Fri, 29 Jul 2022 15:28:16 -0400 Subject: 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 Signed-off-by: Milas Bowman Co-authored-by: Ahmon Dancy --- docker/models/images.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'docker') diff --git a/docker/models/images.py b/docker/models/images.py index e247d35..79ccbe4 100644 --- a/docker/models/images.py +++ b/docker/models/images.py @@ -61,6 +61,24 @@ class Image(Model): """ 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): """ Get a tarball of an image. Similar to the ``docker save`` command. -- cgit v1.2.1