Skip to content

Commit 0a39487

Browse files
Merge pull request #16010 from vrothberg/container-inspect
container inspect: include image digest
2 parents 3feb56e + 02b0f9f commit 0a39487

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

libpod/container_inspect.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,15 @@ func (c *Container) getContainerInspectData(size bool, driverData *define.Driver
166166
IsInfra: c.IsInfra(),
167167
IsService: c.IsService(),
168168
}
169+
170+
if config.RootfsImageID != "" { // May not be set if the container was created with --rootfs
171+
image, _, err := c.runtime.libimageRuntime.LookupImage(config.RootfsImageID, nil)
172+
if err != nil {
173+
return nil, err
174+
}
175+
data.ImageDigest = image.Digest().String()
176+
}
177+
169178
if ctrSpec.Process.Capabilities != nil {
170179
data.EffectiveCaps = ctrSpec.Process.Capabilities.Effective
171180
data.BoundingCaps = ctrSpec.Process.Capabilities.Bounding

libpod/define/container_inspect.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,7 @@ type InspectContainerData struct {
659659
Args []string `json:"Args"`
660660
State *InspectContainerState `json:"State"`
661661
Image string `json:"Image"`
662+
ImageDigest string `json:"ImageDigest"`
662663
ImageName string `json:"ImageName"`
663664
Rootfs string `json:"Rootfs"`
664665
Pod string `json:"Pod"`

test/system/030-run.bats

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -548,11 +548,23 @@ json-file | f
548548
# prior to #8623 `podman run` would error out on untagged images with:
549549
# Error: both RootfsImageName and RootfsImageID must be set if either is set: invalid argument
550550
run_podman untag $IMAGE
551-
run_podman run --rm $imageID ls
552551

552+
run_podman run --rm $randomname $imageID true
553553
run_podman tag $imageID $IMAGE
554554
}
555555

556+
@test "podman inspect includes image data" {
557+
randomname=$(random_string 30)
558+
559+
run_podman inspect $IMAGE --format "{{.ID}} {{.Digest}}"
560+
expected="$IMAGE $output"
561+
562+
run_podman run --name $randomname $IMAGE true
563+
run_podman container inspect $randomname --format "{{.ImageName}} {{.Image}} {{.ImageDigest}}"
564+
is "$output" "$expected"
565+
run_podman rm -f -t0 $randomname
566+
}
567+
556568
@test "Verify /run/.containerenv exist" {
557569
# Nonprivileged container: file exists, but must be empty
558570
run_podman run --rm $IMAGE stat -c '%s' /run/.containerenv
@@ -620,10 +632,15 @@ json-file | f
620632
run_podman image mount $IMAGE
621633
romount="$output"
622634

635+
randomname=$(random_string 30)
623636
# FIXME FIXME FIXME: Remove :O once (if) #14504 is fixed!
624-
run_podman run --rm --rootfs $romount:O echo "Hello world"
637+
run_podman run --name=$randomname --rootfs $romount:O echo "Hello world"
625638
is "$output" "Hello world"
626639

640+
run_podman container inspect $randomname --format "{{.ImageDigest}}"
641+
is "$output" "" "Empty image digest for --rootfs container"
642+
643+
run_podman rm -f -t0 $randomname
627644
run_podman image unmount $IMAGE
628645
fi
629646
}

0 commit comments

Comments
 (0)