diff --git a/compose/cli/main.py b/compose/cli/main.py index 46c6b9652..308ac5bb2 100644 --- a/compose/cli/main.py +++ b/compose/cli/main.py @@ -511,7 +511,10 @@ class TopLevelCommand(object): rows = [] for container in containers: image_config = container.image_config - repo_tags = image_config['RepoTags'][0].rsplit(':', 1) + repo_tags = ( + image_config['RepoTags'][0].rsplit(':', 1) if image_config['RepoTags'] + else ('', '') + ) image_id = image_config['Id'].split(':')[1][:12] size = human_readable_file_size(image_config['Size']) rows.append([ diff --git a/tests/acceptance/cli_test.py b/tests/acceptance/cli_test.py index 502907fe7..74c4e0159 100644 --- a/tests/acceptance/cli_test.py +++ b/tests/acceptance/cli_test.py @@ -2447,14 +2447,30 @@ class CLITestCase(DockerClientTestCase): assert 'multiplecomposefiles_another_1' in result.stdout assert 'multiplecomposefiles_simple_1' in result.stdout + @mock.patch.dict(os.environ) + def test_images_tagless_image(self): + self.base_dir = 'tests/fixtures/tagless-image' + stream = self.client.build(self.base_dir, decode=True) + img_id = None + for data in stream: + if 'aux' in data: + img_id = data['aux']['ID'] + break + if 'stream' in data and 'Successfully built' in data['stream']: + img_id = self.client.inspect_image(data['stream'].split(' ')[2].strip())['Id'] + + assert img_id + + os.environ['IMAGE_ID'] = img_id + self.project.get_service('foo').create_container() + result = self.dispatch(['images']) + assert '' in result.stdout + assert 'taglessimage_foo_1' in result.stdout + def test_up_with_override_yaml(self): self.base_dir = 'tests/fixtures/override-yaml-files' self._project = get_project(self.base_dir, []) - self.dispatch( - [ - 'up', '-d', - ], - None) + self.dispatch(['up', '-d'], None) containers = self.project.containers() self.assertEqual(len(containers), 2) diff --git a/tests/fixtures/tagless-image/Dockerfile b/tests/fixtures/tagless-image/Dockerfile new file mode 100644 index 000000000..567410552 --- /dev/null +++ b/tests/fixtures/tagless-image/Dockerfile @@ -0,0 +1,2 @@ +FROM busybox:latest +RUN touch /blah diff --git a/tests/fixtures/tagless-image/docker-compose.yml b/tests/fixtures/tagless-image/docker-compose.yml new file mode 100644 index 000000000..c4baf2ba1 --- /dev/null +++ b/tests/fixtures/tagless-image/docker-compose.yml @@ -0,0 +1,5 @@ +version: '2.3' +services: + foo: + image: ${IMAGE_ID} + command: top