python - Docker 健康检查总是返回不健康状态

标签 python docker health-check

Docker Healthcheck 失败,因此显示为不健康。

这是Dcokerfile

FROM python:3.8.5-alpine3.12

WORKDIR /app

EXPOSE 8080
ENV FLASK_APP=app.py

COPY . /app
RUN pip install -r requirements.txt

ENTRYPOINT [ "flask"]
HEALTHCHECK --interval=10s --timeout=10s --start-period=55s \
   CMD curl -f --retry 10 --max-time 15 --retry-delay 10 --retry-max-time 60 "http://localhost:8080/health" || exit 1   

CMD [ "run", "--host", "0.0.0.0", "--port",  "8080"]

尝试使用下面的示例,出现以下错误

$docker inspect --format '{{json .State.Health }}' flask-app

Template parsing error: template: :1:13: executing "" at <.State.Health>: map has no entry for key "State"

应用程序.py

from flask import Flask, request
from flask_restx  import fields, Resource, Api, reqparse

app = Flask(__name__)
api = Api(app)
    
@api.route('/health', methods=['GET'])
class Health(Resource):
    def get(self):
        return { 'success': True, 'message': "healthy" }

if __name__ == '__main__':
    app.run(debug=True, host='0.0.0.0')

Health API is working fine

Notice 'Unhealthy' status in the docker ps

最佳答案

您确定您的容器中安装了curl吗?它没有附带 python:3.8.5-alpine3.12

将这些行添加到您的 Dockerfile

RUN apk update && \
    apk add curl
    rm -rf /var/cache/apk/*

关于python - Docker 健康检查总是返回不健康状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67513998/

相关文章:

c# - 基于具有特定接口(interface)的所有服务动态创建健康检查

python - dask groupby 应用然后合并回数据框

python - 卡夫卡与 python : How to send topic to postgreSQL?

python - 生成内置类型值的字典理解

docker - 无效的 header 字段值“运行 docker 镜像时出现 oci 运行时错误

networking - docker:如何轻松获得 veth 桥接接口(interface)对?

ssl - 在通过 authconfig 禁用重新启用 tls 后,客户端上的 openldap tls 身份验证工作

azure - 如何获取 Azure APIM 运行状况检查和详细信息

python - 如何使用 PANDAS/Python 将矩阵转换为列数组

docker 组成 : hundreds of health check processes not terminated