Вопрос:

How do I see container health status for containers from my docker-compose file

docker docker-compose go-templates

1254 просмотра

1 ответ

697 Репутация автора

Since docker-compose 1.10.0 there is support for health checks. I started implementing those in one of my docker-compose files.

There are a couple sites where it is suggested that health status of a container can be seen from docker ps. See below.

However, I don't see any health status when running docker ps. An excerpt of my docker-compose file looks like:

version: "2.1"

services:

  my-service:
    container_name: my-service
    image: "our-registry:5000/my-service:1.0.1"
    expose: [3000]
    restart: always
    depends_on:
      - other-service-1
      - other-service-2
    healthcheck:
      test: ["nc", "-z", "127.0.0.1", "3000", "||", "exit", "1"]
      interval: "2s"
      timeout: "1

An excerpt of my docker ps output looks like:

# docker ps
CONTAINER ID        IMAGE                                  COMMAND                  CREATED             STATUS              PORTS          NAMES
af680b9fc6c3        our-registry/pr-georegion:1.0.1        "node index.js"          8 minutes ago       Up 8 minutes        3000/tcp       pr-georegion

Docker and docker-compose versions:

# docker -v
Docker version 1.12.6, build 78d1802
# docker-compose -v
docker-compose version 1.10.1, build b252738

Example 1

Example 1

Example 2

enter image description here

Автор: jleeothon Источник Размещён: 03.02.2017 12:01

Ответы (1)


3 плюса

697 Репутация автора

Решение

I found the problem in my docker-compose file. From the [official docs](test must be either a string or a list. If it’s a list, the first item must be either NONE, CMD or CMD-SHELL. If it’s a string, it’s equivalent to specifying CMD-SHELL followed by that string.):

test must be either a string or a list. If it’s a list, the first item must be either NONE, CMD or CMD-SHELL. If it’s a string, it’s equivalent to specifying CMD-SHELL followed by that string.

So I changed:

test: ["nc", "-z", "127.0.0.1", "3000", "||", "exit", "1"]

for:

test: ["CMD-SHELL", "nc -z 127.0.0.1 3000 || exit 1"]
Автор: jleeothon Размещён: 03.02.2017 02:25
Вопросы из категории :
32x32