Dockerfile健康检查写法

Dockerfile

FROM tomcat

MAINTAINER linjb@fline88.com

ADD bitcoin.war /usr/local/tomcat/webapps

RUN  rm -rf /root/a.outi

HEALTHChECK --interval=10s --timeout=4s --retries=3 CMD curl -fs http://127.0.0.1:8080/bitcoin/ || exit 1

CMD ["catalina.sh","run"]

EXPOSE 8080

解释: HEALTHChECK 后加参数 –interval 间隔 –timeout 命令运行时常 –retries 尝试次数 CMD 运行的命令

使用此种方式构建出来的镜像在运行时会定时进行健康检查

[root@epoll linjb]# docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                   PORTS                    NAMES
5d7b5263561a        1bfe14e2d0e1        "catalina.sh run"   4 minutes ago       Up 4 minutes (healthy)   0.0.0.0:9002->8080/tcp   mystifying_nightingale
1ecb4da2e83d        85491768940f        "catalina.sh run"   20 minutes ago      Up 20 minutes            0.0.0.0:9001->8080/tcp   focused_leakey
[root@epoll linjb]#

区别如上