diff --git a/libimage/image_test.go b/libimage/image_test.go index bf3ea4083..51e9ae67a 100644 --- a/libimage/image_test.go +++ b/libimage/image_test.go @@ -168,6 +168,25 @@ func TestImageFunctions(t *testing.T) { require.Equal(t, image.NamesHistory(), imageData.NamesHistory, "inspect data should match") } +func TestInspectHealthcheck(t *testing.T) { + runtime, cleanup := testNewRuntime(t) + defer cleanup() + ctx := context.Background() + + imageName := "quay.io/libpod/healthcheck:config-only" + pullOptions := &PullOptions{} + pullOptions.Writer = os.Stdout + pulledImages, err := runtime.Pull(ctx, imageName, config.PullPolicyAlways, pullOptions) + require.NoError(t, err) + require.Len(t, pulledImages, 1) + image := pulledImages[0] + + // Now compare the inspect data to what we expect. + imageData, err := image.Inspect(ctx, nil) + require.NotNil(t, imageData.HealthCheck, "health check should be found in config") + require.Equal(t, []string{"CMD-SHELL", "curl -f http://localhost/ || exit 1"}, imageData.HealthCheck.Test, "health check should be found in config") +} + func TestTag(t *testing.T) { // Note: this will resolve pull from the GCR registry (see // testdata/registries.conf). diff --git a/libimage/inspect.go b/libimage/inspect.go index 007cbdd89..d44ebf46e 100644 --- a/libimage/inspect.go +++ b/libimage/inspect.go @@ -187,7 +187,12 @@ func (i *Image) Inspect(ctx context.Context, options *InspectOptions) (*ImageDat return nil, err } data.Comment = dockerManifest.Comment + // NOTE: Health checks may be listed in the container config or + // the config. data.HealthCheck = dockerManifest.ContainerConfig.Healthcheck + if data.HealthCheck == nil { + data.HealthCheck = dockerManifest.Config.Healthcheck + } } if data.Annotations == nil {