I'm trying to use a Docker HEALTHCHECK in a container. I'm setting that up in a version 3 docker-compose file, which also supports healthcheck:
version: '3'
services:
api:
[...]
healthcheck:
test: test ! -e /unhealthy
interval: 10s
timeout: 1s
retries: 1
In every place I can find, including on stackoverflow, the way to check the health of a container is to use docker inspect
and look at State.Health
, but no such entry exists:
$ docker inspect --format='{{json .State}}' api
Template parsing error: template: :1:7: executing "" at <.State>: map has no entry for key "State"
I googled around for quite a while but cannot see where this information moved to or any alternate ways to check health status.
Version info:
$ docker-compose --version
docker-compose version 1.16.1, build 6d1ac219
$ docker --version
Docker version 17.09.0-ce, build afdb6d4
The service name api
is a compose construct. Docker isn't able to map the name api
to a container. I suspect you have another object named api
that docker inspect
it is looking up.
Compose containers are normally named {{parent_directory}}_{{service}}_{{n}}
. To find the name use:
docker-compose ps
docker ps -a --filter name=SERVICE_NAME
Then you can use inspect on that name
docker inspect --format='{{json .State}}' CONTAINER_ID_OR_NAME
or specifically inspect containers to avoid non container objects:
docker container inspect --format='{{json .State}}' CONTAINER_ID_OR_NAME
All containers should have the .State
object. Only containers with a healthcheck defined will have the .State.Health
data.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With