Reputation: 2273
Docker Version 1.12
,
I got a Dockerfile
from Here
FROM nginx:latest
RUN touch /marker
ADD ./check_running.sh /check_running.sh
RUN chmod +x /check_running.sh
HEALTHCHECK --interval=5s --timeout=3s CMD ./check_running.sh
I'm able to roll the updates and health checks with check_running.sh
shell script. Here, the check_running.sh
script is copied to image
, so the launched container has it.
Now, my question is there any way to Health Check from out side of the container and script also located outside.
I'm excepting a health check command to get the container performance(Depends on what we wrote in script), IF the container is not performing good it should roll-back to previous version ( Kind of a process that monitors the containers, if it is not good, it should roll-back to previous)
Thanks
Upvotes: 7
Views: 13249
Reputation: 271
is there any way to Health Check from out side of the container and script also located outside.
Kind of a process that monitors the containers, if it is not good, it should roll-back to previous
You have several options:
cat script.sh | docker exec -it container sh -s
.ps -Zax
or try looking for children of the daemon), or you can give each container a specific user ID with --user 12345
and then look for that or e.g. connecting to its services. You'd have to make sure it's running inside the right container. You can access the containers' filesystem below /var/lib/docker/devicemapper/mnt/<hash>/rootfs
.docker inspect --format='{{json .State.Health.Status}}' <containername>
combined with e.g. a line in the Dockerfile:
HEALTHCHECK CMD wget -q -s http://some.host
to check the container has internet access.I'd recommend option 3, because it's likely to be more compatible with other tools in the future.
Upvotes: 5
Reputation: 3018
The Docker inspect command lets you view the output of commands that succeed or fail
docker inspect --format='{{json .State.Health}}' your-container-name
Upvotes: 3
Reputation: 2273
Just got comment from a blog!. He refered Docker documentation HealthCheck section. There is a health check "option" for docker
command to "override" the dockerfile defaults. I have not checked yet!. But it seems good for me to get what I want. Will check and update the answer!
Upvotes: 2
Reputation: 105
You can view the results of the health check by running docker inspect
on a container.
Another approach depending on your application would be to expose a /healthz
endpoint that the healthcheck also probes, this way it can be queried externally or internally as needed.
Upvotes: 0
Reputation: 263636
That's not available with the Dockerfile HEALTHCHECK
option, all checks run inside the container. To me, this is a good thing since it avoids potentially untrusted code running directly on the host, and it allows you to include the dependencies for the health check inside your container.
If you need to monitor your container from outside, you'll need to use another tool or monitoring application, there are quite a few of them out there.
Upvotes: 0