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 <navid9675@gmail.com>
This commit is contained in:
Navid Ali Pour 2020-08-08 11:38:23 -06:00
parent b4beaaac8c
commit b37a25d70b
1 changed files with 7 additions and 1 deletions

View File

@ -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):