From b37a25d70b7d483cc0fbc78fb6863636ca84cbb3 Mon Sep 17 00:00:00 2001 From: Navid Ali Pour Date: Sat, 8 Aug 2020 11:38:23 -0600 Subject: [PATCH] Fix pulling with container create api Fix the pulling issue stated in #2635. Basically, similar to `docker create` it should pull the image if it does not exist locally. Signed-off-by: Navid Ali Pour --- docker/models/containers.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/docker/models/containers.py b/docker/models/containers.py index 0c2b855a..ae417455 100644 --- a/docker/models/containers.py +++ b/docker/models/containers.py @@ -864,8 +864,14 @@ class ContainerCollection(Collection): kwargs['image'] = image kwargs['command'] = command kwargs['version'] = self.client.api._version + platform = kwargs.pop('platform', None) create_kwargs = _create_container_args(kwargs) - resp = self.client.api.create_container(**create_kwargs) + try: + resp = self.client.api.create_container(**create_kwargs) + except ImageNotFound: + self.client.images.pull(image, platform=platform) + resp = self.client.api.create_container(**create_kwargs) + return self.get(resp['Id']) def get(self, container_id):