mirror of https://github.com/docker/compose.git
Merge pull request #6209 from docker/images-use-service-tag
Images use service tag
This commit is contained in:
commit
30afcc4994
|
@ -568,31 +568,43 @@ class TopLevelCommand(object):
|
||||||
if options['--quiet']:
|
if options['--quiet']:
|
||||||
for image in set(c.image for c in containers):
|
for image in set(c.image for c in containers):
|
||||||
print(image.split(':')[1])
|
print(image.split(':')[1])
|
||||||
else:
|
return
|
||||||
headers = [
|
|
||||||
'Container',
|
def add_default_tag(img_name):
|
||||||
'Repository',
|
if ':' not in img_name.split('/')[-1]:
|
||||||
'Tag',
|
return '{}:latest'.format(img_name)
|
||||||
'Image Id',
|
return img_name
|
||||||
'Size'
|
|
||||||
]
|
headers = [
|
||||||
rows = []
|
'Container',
|
||||||
for container in containers:
|
'Repository',
|
||||||
image_config = container.image_config
|
'Tag',
|
||||||
repo_tags = (
|
'Image Id',
|
||||||
image_config['RepoTags'][0].rsplit(':', 1) if image_config['RepoTags']
|
'Size'
|
||||||
else ('<none>', '<none>')
|
]
|
||||||
)
|
rows = []
|
||||||
image_id = image_config['Id'].split(':')[1][:12]
|
for container in containers:
|
||||||
size = human_readable_file_size(image_config['Size'])
|
image_config = container.image_config
|
||||||
rows.append([
|
service = self.project.get_service(container.service)
|
||||||
container.name,
|
index = 0
|
||||||
repo_tags[0],
|
img_name = add_default_tag(service.image_name)
|
||||||
repo_tags[1],
|
if img_name in image_config['RepoTags']:
|
||||||
image_id,
|
index = image_config['RepoTags'].index(img_name)
|
||||||
size
|
repo_tags = (
|
||||||
])
|
image_config['RepoTags'][index].rsplit(':', 1) if image_config['RepoTags']
|
||||||
print(Formatter().table(headers, rows))
|
else ('<none>', '<none>')
|
||||||
|
)
|
||||||
|
|
||||||
|
image_id = image_config['Id'].split(':')[1][:12]
|
||||||
|
size = human_readable_file_size(image_config['Size'])
|
||||||
|
rows.append([
|
||||||
|
container.name,
|
||||||
|
repo_tags[0],
|
||||||
|
repo_tags[1],
|
||||||
|
image_id,
|
||||||
|
size
|
||||||
|
])
|
||||||
|
print(Formatter().table(headers, rows))
|
||||||
|
|
||||||
def kill(self, options):
|
def kill(self, options):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -2770,3 +2770,13 @@ class CLITestCase(DockerClientTestCase):
|
||||||
with pytest.raises(DuplicateOverrideFileFound):
|
with pytest.raises(DuplicateOverrideFileFound):
|
||||||
get_project(self.base_dir, [])
|
get_project(self.base_dir, [])
|
||||||
self.base_dir = None
|
self.base_dir = None
|
||||||
|
|
||||||
|
def test_images_use_service_tag(self):
|
||||||
|
pull_busybox(self.client)
|
||||||
|
self.base_dir = 'tests/fixtures/images-service-tag'
|
||||||
|
self.dispatch(['up', '-d', '--build'])
|
||||||
|
result = self.dispatch(['images'])
|
||||||
|
|
||||||
|
assert re.search(r'foo1.+test[ \t]+dev', result.stdout) is not None
|
||||||
|
assert re.search(r'foo2.+test[ \t]+prod', result.stdout) is not None
|
||||||
|
assert re.search(r'foo3.+_foo3[ \t]+latest', result.stdout) is not None
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
FROM busybox:latest
|
||||||
|
RUN touch /foo
|
|
@ -0,0 +1,10 @@
|
||||||
|
version: "2.4"
|
||||||
|
services:
|
||||||
|
foo1:
|
||||||
|
build: .
|
||||||
|
image: test:dev
|
||||||
|
foo2:
|
||||||
|
build: .
|
||||||
|
image: test:prod
|
||||||
|
foo3:
|
||||||
|
build: .
|
Loading…
Reference in New Issue