Skip to content

Can docker-compose ps show health status? #5525

Closed

Description

@AnthonyMastrean

The Docker CLI can show health status

$ docker container ls --filter name=example_example_1
CONTAINER ID        IMAGE            COMMAND                  CREATED             STATUS                 PORTS                                     NAMES
6e9eef9909f7        example:latest   "nginx -g 'daemon ..."   5 hours ago         Up 5 hours (healthy)   80/tcp, 443/tcp, 0.0.0.0:8080->8080/tcp   example_example_1

But, the Docker Compose CLI does not

$ docker-compose ps example
         Name            Command          State                       Ports
------------------------------------------------------------------------------------------------
example_example_1   nginx -g daemon off;   Up      443/tcp, 80/tcp, 0.0.0.0:8080->8080/tcp

It might be nice to display the same health status, especially for those of us using Compose 2.1 and the depends_on / condition / service_healthy feature.

Activity

  1. AnthonyMastrean commented on Jan 8, 2018

    @AnthonyMastrean
    Author

    It looks like this method, human_readable_state, would need to be enhanced to display health status if this service has a HEALTHCHECK defined. As stated at the beginning of the class, the dictionary of internal state is coming from the Docker engine API (Inspect a container).

    GET /containers/{id}/json
    

    But, I'm not quite sure that API endpoint returns the current health status. I don't see any "health" properties, even on the State (although, maybe the example is incomplete).

      "State": {
        "Error": "",
        "ExitCode": 9,
        "FinishedAt": "2015-01-06T15:47:32.080254511Z",
        "OOMKilled": false,
        "Dead": false,
        "Paused": false,
        "Pid": 0,
        "Restarting": false,
        "Running": true,
        "StartedAt": "2015-01-06T15:47:32.072697474Z",
        "Status": "running"
      },

    Perhaps, we can use the same call as the service_healthy feature, to get the container's health status directly from inspect and construct the new status string?

  2. bosorawis commented on Jan 29, 2018

    @bosorawis

    @AnthonyMastrean Looks like inspect API endpoint does return Health status if "healthcheck" is specified for the container.

        "State": {
            "Status": "running",
            "Running": true,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 6997,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2018-01-29T00:08:00.1885465Z",
            "FinishedAt": "0001-01-01T00:00:00Z",
            "Health": {
                "Status": "starting",
                "FailingStreak": 0,
                "Log": []
            }
        }
    

    I could try adding health property for container object and construct new status string from there.

  3. bosorawis commented on Jan 29, 2018

    @bosorawis

    Should I also add time portion of the status string as well? Like Up for ......... (health), or just
    Up (health) is fine?

  4. AnthonyMastrean commented on Jan 29, 2018

    @AnthonyMastrean
    Author

    I think adding just the health status is OK for now. I don't know if it's Compose's intent to mirror the entire status string.

    Note that the Docker CLI shows a bit of a custom message if the healthcheck is still inside of the "starting" period. The health status is technically just starting, but it prints health: starting.

    STATUS
    Up Less than a second (health: starting)
    

    Afterwards, it just shows the raw health status (like healthy).

    STATUS
    Up About a minute (healthy)
    

    You might replicate this behavior, at least.

  5. bosorawis commented on Feb 3, 2018

    @bosorawis

    I created a Pull Request for this change. Decided to go with similar behavior as @AnthonyMastrean mentioned above regarding the health: starting. Did not add the Up for .....

  6. added this to the 1.20.0 milestone on Feb 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions