Search code examples
dockerdocker-composeminio

Minio container is unhealthy even when I get status 200 with curl


I have a docker compose with diferent services.

  # Minio storage service
  findra-minio:
    container_name: findra-minio
    image: minio/minio
    command: server /data --console-address ":${FORWARD_MINIO_CONSOLE_PORT:-9002}" --address ":${FORWARD_MINIO_PORT:-9001}"
    ports:
      - '${FORWARD_MINIO_PORT:-9001}:9001'
      - '${FORWARD_MINIO_API_PORT:-9002}:9002'
    environment:
      MINIO_ROOT_USER: ${MINIO_ROOT_USER}
      MINIO_ROOT_PASSWORD: ${MINIO_ROOT_PASSWORD}
    healthcheck:
      test: ["CMD", "curl -k -f http://127.0.0.1:9001/minio/health/live || exit 1"]
      interval: 30s
      timeout: 10s
      retries: 5
    volumes:
      - type: volume
        source: findra_minio
        target: /data
    networks:
      - backend

  # Redis database for caching
  findra-redis:
    image: redis:7-alpine
    container_name: findra-redis
    restart: unless-stopped
    volumes:
      - type: volume
        source: findra_redis
        target: /data
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 30s
      timeout: 10s
      retries: 5
    networks:
      - backend

and the MinIO container is unhealthy, and even when I run curl -I http://127.0.0.1:9001/minio/health/live , it returns a status 200.

HTTP/1.1 200 OK
Accept-Ranges: bytes
Content-Length: 0
Server: MinIO
Strict-Transport-Security: max-age=31536000; includeSubDomains
Vary: Origin
X-Amz-Id-2: 7987905dee74cdeb212432486a178e511309594cee7cb75f892cd53e35f09ea4
X-Amz-Request-Id: 17E63796A4A97415
X-Content-Type-Options: nosniff
X-Xss-Protection: 1; mode=block
Date: Sun, 28 Jul 2024 00:03:47 GMT

If I do docker ps we can see:

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f4d5ae1dec37 minio/minio "/usr/bin/docker-ent…" 4 minutes ago Up 4 minutes (unhealthy) 9000/tcp, 0.0.0.0:9001-9002->9001-9002/tcp findra-minio
22a064519dd1 mysql:8 "docker-entrypoint.s…" 4 minutes ago Up 4 minutes (healthy) 3306/tcp, 33060/tcp, 0.0.0.0:3307->3307/tcp findra-mysql-testing
2164d1160ab5 redis:7-alpine "docker-entrypoint.s…" 4 minutes ago Up 4 minutes (healthy) 6379/tcp findra-redis
e5a891311f8f mysql:8 "docker-entrypoint.s…" 4 minutes ago Up 4 minutes (healthy) 0.0.0.0:3306->3306/tcp, 33060/tcp findra-mysql

The difference I can see is that the command in MinIO is different from the others.


Solution

  • You have specified a CMD test, which expects a simple command, but you're passing in a shell script.

    You can see the logs from your healthcheck command by running docker container inspect <name>, and looking at the .State.Health field. If you look at the docker container inspect output for the findra-minio container, you'll see:

    "Health": {
        "Status": "starting",
        "FailingStreak": 1,
        "Log": [
            {
                "Start": "2024-07-27T20:59:49.803139331-04:00",
                "End": "2024-07-27T20:59:49.844207315-04:00",
                "ExitCode": -1,
                "Output": "OCI runtime exec failed: exec failed: unable to start container process: exec: \"curl -k -f http://127.0.0.1:9001/minio/health/live || exit 1\": stat curl -k -f http://127.0.0.1:9001/minio/health/live || exit 1: no such file or directory: unknown"
            }
        ]
    }
    

    The error message means that Docker is looking for an executable file named curl -k -f http... || exit 1, and of course no such file exists.

    If your healthcheck is a shell script, you need to use a CMD-SHELL test:

        healthcheck:
          test: ["CMD-SHELL", "curl -k -f http://127.0.0.1:9001/minio/health/live || exit 1"]
    

    The compose reference says:

    It can 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 you could also write:

        healthcheck:
          test: "curl -k -f http://127.0.0.1:9001/minio/health/live || exit 1"