Docker Inspect - Template parsing error for .State.Health.Status

Hey everyone,
I’ve been trying to inspect the health of every docker container that is currently running and I am having some issues when trying to execute the command docker container inspect -f '{{.State.Health.Status}}' <container name>.
Sometimes it returns the state while at other times it just results in a template parsing error, which says that there is no entry for key “Health” looking something like this:

Template parsing error: template: :1:9: executing "" at <.State.Health.Status>: map has no entry for key "Health"

Does anyone have an idea why docker container inspect behaves like this at times? Can I somehow force a container to have an entry for Health?

I am using Docker Desktop for Windows Version 4.1.1 with the WSL 2 based engine

Thanks in advance

Is this happening inspecting always the same container? If there is a healthcheck, it should always work. If there is no Healthcheck, it should never work. In case of multiple containers you can try this to avoid error messages:

docker container inspect -f '{{if .State.Health}}{{.State.Health.Status}}{{else}}undefined{{end}}'

I know this is an old issue, but I’m getting an error when I try that: template parsing error: template: :1:438: executing "" at <.State.Health>: map has no entry for key "Health"