diff --git a/compose/cli/main.py b/compose/cli/main.py index 4c18d19f7..07447d671 100644 --- a/compose/cli/main.py +++ b/compose/cli/main.py @@ -356,9 +356,9 @@ class TopLevelCommand(object): h = options['--hash'] self.project = project_from_options('.', self.toplevel_options) services = [svc for svc in options['--hash'].split(',')] if h != '*' else None - - for service in self.project.get_services(services): - print('{} {}'.format(service.name, service.config_hash)) + with errors.handle_connection_errors(self.project.client): + for service in self.project.get_services(services): + print('{} {}'.format(service.name, service.config_hash)) return print(serialize_config(compose_config, image_digests)) diff --git a/compose/service.py b/compose/service.py index e77780fd8..a31f75a3d 100644 --- a/compose/service.py +++ b/compose/service.py @@ -656,9 +656,15 @@ class Service(object): return json_hash(self.config_dict()) def config_dict(self): + def image_id(): + try: + return self.image()['Id'] + except NoSuchImageError: + return None + return { 'options': self.options, - 'image_id': self.image()['Id'], + 'image_id': image_id(), 'links': self.get_link_names(), 'net': self.network_mode.id, 'networks': self.networks, diff --git a/tests/acceptance/cli_test.py b/tests/acceptance/cli_test.py index 815b92c8d..f9d2821b0 100644 --- a/tests/acceptance/cli_test.py +++ b/tests/acceptance/cli_test.py @@ -224,7 +224,6 @@ class CLITestCase(DockerClientTestCase): def test_config_with_hash_option(self): self.base_dir = 'tests/fixtures/v2-full' - self.project.build() result = self.dispatch(['config', '--hash=*']) for service in self.project.get_services(): assert '{} {}\n'.format(service.name, service.config_hash) in result.stdout