Docker群组健康检查失败会杀死容器-退出0

时间:2020-05-19 12:10:35

标签: docker docker-swarm

我有一个运行着使用以下Dockerfile构建的基本节点应用程序映像的Docker集群

# Use the official image as a parent image.
FROM node:current

# Set the working directory.
WORKDIR /usr/src/app

# Copy the file from your host to your current location.
COPY package.json .

# Run the command inside your image filesystem.
RUN npm install

# Inform Docker that the container is listening on the specified port at runtime.
EXPOSE 8080

# Run the specified command within the container.
CMD [ "npm", "start" ]

# Copy the rest of your app's source code from your host to your image filesystem.
COPY . .

#HEALTHCHECK --interval=10s --timeout=3s CMD curl --fail http://localhost:8080/health || exit 1

我使用以下docker堆栈文件运行docker swarm服务:

version: "3"
services:

  webapp:
    image: testapp:broken
    ports:
      - 8081:8080
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8080/health"]
      interval: 10s
      timeout: 2s
      retries: 3
    deploy:
      replicas: 1
      update_config:
        parallelism: 2
        delay: 10s
      restart_policy:
        condition: on-failure

如果curl命令成功,则一切正常。但是,如果我删除了/health路由,则状态不会从health: starting变为unhealthy,它会直接杀死该容器。

我该如何解决?我也尝试过 test: ["CMD", "curl -f http://localhost:8080/health || exit 1"]的方法,但是没有运气。

编辑:该容器显示为已退出

    CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                     PORTS               NAMES
73fce379163c        testapp:broken      "docker-entrypoint.s…"   6 minutes ago       Exited (0) 6 minutes ago                       testapp_webapp.1.oqdg1uuxgk52end0h9ady7tpz

具有以下状态:

"State": {
            "Status": "exited",
            "Running": false,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 0,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2020-05-19T13:17:10.39992571Z",
            "FinishedAt": "2020-05-19T13:17:42.824012295Z",
            "Health": {
                "Status": "unhealthy",
                "FailingStreak": 3,
                "Log": [
                    {
                        "Start": "2020-05-19T13:17:20.400938593Z",
                        "End": "2020-05-19T13:17:20.495914152Z",
                        "ExitCode": 22,
                        "Output": "  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current\n                                 Dload  Upload   Total   Spent    Left  Speed\n\r  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0\r  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0\ncurl: (22) The requested URL returned error: 404 Not Found\n"
                    },
                    {
                        "Start": "2020-05-19T13:17:30.50796682Z",
                        "End": "2020-05-19T13:17:30.635482465Z",
                        "ExitCode": 22,
                        "Output": "  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current\n                                 Dload  Upload   Total   Spent    Left  Speed\n\r  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0\r  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0\ncurl: (22) The requested URL returned error: 404 Not Found\n"
                    },
                    {
                        "Start": "2020-05-19T13:17:40.654745233Z",
                        "End": "2020-05-19T13:17:40.744164595Z",
                        "ExitCode": 22,
                        "Output": "  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current\n                                 Dload  Upload   Total   Spent    Left  Speed\n\r  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0\r  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0\ncurl: (22) The requested URL returned error: 404 Not Found\n"
                    }
                ]
            }
        },

0 个答案:

没有答案