FROM couchbase:latest
COPY configure-node.sh /opt/couchbase
HEALTHCHECK --interval=5s --timeout=3s CMD curl --fail http://localhost:8091/pools || exit 1
CMD ["/opt/couchbase/configure-node.sh"]
The can be:
–interval=DURATION (default 30s).
–timeout=DURATION (default 30s).
–retries=N (default 3).
–start_period=10s
–retries=3
HEALTHCHECK
同样的也可以对service进行更改
sudo docker service update artifactory_daeartifactory --health-cmd=" curl --fail http://localhost:8081 || exit 1" --health-interval=60s --health-timeout=30s --health-retries=3
https://zhuanlan.zhihu.com/p/28911530
https://codeblog.dotsandbrackets.com/docker-health-check/
https://docs.docker.com/engine/reference/commandline/service_update/
关于healthy check的解释
You setup healthchecks the same ways your first link suggests. All those ways will tell docker what command to run, how often to run it, etc.
If you use docker run to start a container, the UI will show unhealthy when healthchecks fail, but docker will do nothing to the container. It’s up to you or some higher level monitoring solution to act on it.
If you use docker service create (or docker stack deploy) to create a Swarm service and that healthcheck fails, it will stop/kill the task (container) and reschedule a new task to replace that replica of the service. During the stop/kill (it tries to gracefully stop it, but kills after 10s like all docker containers), Swarm will stop overlay inbound traffic to that task like it does for all stopping tasks.