mirror of
https://github.com/docker/compose.git
synced 2025-07-23 05:34:36 +02:00
Pull images if they do not exist
This commit is contained in:
parent
785cb12833
commit
24a98b0552
@ -1,3 +1,4 @@
|
||||
from docker.client import APIError
|
||||
import logging
|
||||
import re
|
||||
|
||||
@ -34,8 +35,19 @@ class Service(object):
|
||||
self.stop_container()
|
||||
|
||||
def create_container(self, **override_options):
|
||||
"""
|
||||
Create a container for this service. If the image doesn't exist, attempt to pull
|
||||
it.
|
||||
"""
|
||||
container_options = self._get_container_options(override_options)
|
||||
return self.client.create_container(**container_options)
|
||||
try:
|
||||
return self.client.create_container(**container_options)
|
||||
except APIError, e:
|
||||
if e.response.status_code == 404 and e.explanation and 'No such image' in e.explanation:
|
||||
log.info('Pulling image %s...' % container_options['image'])
|
||||
self.client.pull(container_options['image'])
|
||||
return self.client.create_container(**container_options)
|
||||
raise
|
||||
|
||||
def start_container(self, container=None, **override_options):
|
||||
container_options = self._get_container_options(override_options)
|
||||
|
Loading…
x
Reference in New Issue
Block a user