Skip to content

Running container is considered unhealthy #113

Open
@mshero

Description

@mshero

Proposal

The Problem

When running running the image with a custom port, the docker system considers the container as unhealthy though it is not. In fact the __admin/health endpoint returns `status: "healthy".

Expected

When running the image with a custom port the docker system considers the container as healthy.

Actual Behavior

The docker system considers the container unhealthy.

Reproduction steps

Start the WireMock image - spoiler shows expected output

$ docker run -it --rm -p 8089:8089 -e WIREMOCK_OPTIONS='--port 8089' wiremock/wiremock

██     ██ ██ ██████  ███████ ███    ███  ██████   ██████ ██   ██ 
██     ██ ██ ██   ██ ██      ████  ████ ██    ██ ██      ██  ██  
██  █  ██ ██ ██████  █████   ██ ████ ██ ██    ██ ██      █████   
██ ███ ██ ██ ██   ██ ██      ██  ██  ██ ██    ██ ██      ██  ██  
 ███ ███  ██ ██   ██ ███████ ██      ██  ██████   ██████ ██   ██ 

----------------------------------------------------------------
|               Cloud: https://wiremock.io/cloud               |
|                                                              |
|               Slack: https://slack.wiremock.org              |
----------------------------------------------------------------

version:                      3.9.1
port:                         8089
enable-browser-proxying:      false
disable-banner:               false
no-request-journal:           false
verbose:                      false

extensions:                   response-template,webhook

Check health endpoint - also here everything looks fine

$ curl -sS -X GET http://localhost:8089/__admin/health | jq
{
  "status": "healthy",
  "message": "Wiremock is ok",
  "version": "3.9.1",
  "uptimeInSeconds": 56,
  "timestamp": "2024-09-06T13:39:53.020787Z"
}

Check docker container - status states (unhealthy)

$ docker ps 
CONTAINER ID   IMAGE               COMMAND                  CREATED              STATUS                          PORTS                                        NAMES
a482d4afd42b   wiremock/wiremock   "/docker-entrypoint.…"   About a minute ago   Up About a minute (unhealthy)   8080/tcp, 8443/tcp, 0.0.0.0:8089->8089/tcp   confident_goodall

At this point one could state this doesn't look as a big issue as the container is up and running and serving as expected. The problem manifests rather when WireMock is set up utilizing docker compose.

Example docker-compose.yaml

services:
  wiremock:
    image: wiremock/wiremock
    container_name: wiremock-local
    entrypoint: [ "/docker-entrypoint.sh", "--port=8089"]
    ports:
      - "8089:8089"

And the docker compose command that fails

$ docker compose up --wait
[+] Building 0.0s (0/0)                                                                                                                                                  
[+] Running 0/1
 ⠿ Container wiremock-main  Waiting                                                                                                                                90.8s 
container wiremock-main is unhealthy

References

A brief investigation (docker inspect) of the running container pointed to the underlying problem

$ docker inspect confident_goodall
...
            "Health": {
                "Status": "unhealthy",
                "FailingStreak": 31,
                "Log": [
                    {
                        "Start": "2024-09-06T16:07:05.878727105+02:00",
                        "End": "2024-09-06T16:07:06.012145585+02:00",
                        "ExitCode": 1,
                        "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: (7) Failed to connect to localhost port 8080 after 2 ms: Couldn't connect to server\n"
                    },
                    {
                        "Start": "2024-09-06T16:07:36.019068045+02:00",
                        "End": "2024-09-06T16:07:36.110571656+02:00",
                        "ExitCode": 1,
                        "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: (7) Failed to connect to localhost port 8080 after 2 ms: Couldn't connect to server\n"
                    },
                    {
                        "Start": "2024-09-06T16:08:06.115316283+02:00",
                        "End": "2024-09-06T16:08:06.242779708+02:00",
                        "ExitCode": 1,
                        "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: (7) Failed to connect to localhost port 8080 after 2 ms: Couldn't connect to server\n"
                    },
                    {
                        "Start": "2024-09-06T16:08:36.249012972+02:00",
                        "End": "2024-09-06T16:08:36.387739973+02:00",
                        "ExitCode": 1,
                        "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: (7) Failed to connect to localhost port 8080 after 2 ms: Couldn't connect to server\n"
                    },
                    {
                        "Start": "2024-09-06T16:09:06.393761069+02:00",
                        "End": "2024-09-06T16:09:06.498217177+02:00",
                        "ExitCode": 1,
                        "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: (7) Failed to connect to localhost port 8080 after 2 ms: Couldn't connect to server\n"
                    }
                ]
            }
...
            "Healthcheck": {
                "Test": [
                    "CMD-SHELL",
                    "curl -f http://localhost:8080/__admin/health || exit 1"
                ],
                "StartPeriod": 5000000000
            },
...

Docker engine in use

$ docker version
Client: Docker Engine - Community
 Version:           24.0.2
 API version:       1.43
 Go version:        go1.20.4
 Git commit:        cb74dfc
 Built:             Thu May 25 21:52:13 2023
 OS/Arch:           linux/amd64
 Context:           default

Server: Docker Engine - Community
 Engine:
  Version:          24.0.2
  API version:      1.43 (minimum version 1.12)
  Go version:       go1.20.4
  Git commit:       659604f
  Built:            Thu May 25 21:52:13 2023
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.21
  GitCommit:        3dce8eb055cbb6872793272b4f20ed16117344f8
 runc:
  Version:          1.1.7
  GitCommit:        v1.1.7-0-g860f061
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions