1 创建docker文件夹以及dockerfile文件
2 写入内容
FROM redis
ADD docker-healthcheck.sh /opt/
HEALTHCHECK --interval=10s --timeout=5s --retries=3 CMD /bin/bash /opt/docker-healthcheck.sh
创建 docker-healthcheck.sh
写入内容
#!/bin/bash
set -eo pipefail
host="$(hostname -i || echo '127.0.0.1')"
redisPWD="123456"
if ping="$(redis-cli -h "$host" -a "$redisPWD" 2>/dev/null ping)" && [ "$ping" = 'PONG' ]; then
exit 0
else
exit 1
fi
到目录下
docker build -f dockerfile -t 镜像名:tag名 .
即可生成镜像
docker run执行
需要先给redis 配置密码授权
ConFIG SET requirepass 123456
auth 123456
ConFIG GET requirepass
GitHub - docker-library/healthcheck: https://github.com/docker/docker/issues/21142 prototypes
带有healthecheck dockerfile的镜像