はじめに
Dockerにより、MinIOの構築を行った際に、特定のバージョンのイメージを使うとhealthcheckに失敗する事象が発生しました。
事象の再現
version: "3.7"
x-environment: &environment
MINIO_ROOT_USER: miniouser
MINIO_ROOT_PASSWORD: miniopass
MINIO_BUCKET_NAME: test-bucket
services:
minio:
image: minio/minio:RELEASE.2023-11-01T18-37-25Z
container_name: minio
hostname: minio
volumes:
- ./minio/data:/data
ports:
- "9000:9000"
- "9001:9001"
environment: *environment
command: ['server', '/data', '--console-address', ':9001']
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"]
interval: 1s
timeout: 10s
retries: 5
createbuckets:
image: minio/mc:latest
container_name: createbuckets
hostname: createbuckets
depends_on:
minio:
condition: service_healthy
environment: *environment
# healthcheckしているのでuntil...は不要かも
entrypoint: >
/bin/sh -c "
until (/usr/bin/mc config host add myminio http://minio:9000 $$MINIO_ROOT_USER $$MINIO_ROOT_PASSWORD) do echo '...waiting...' && sleep 1; done;
/usr/bin/mc mb myminio/$$MINIO_BUCKET_NAME;
/usr/bin/mc anonymous set none myminio/$$MINIO_BUCKET_NAME;
exit 0
"
RELEASE.2023-11-01T18-37-25Z
を利用すると、以下のようなエラーが発生し、createbuckets
コンテナの起動に失敗します。
ERROR: for createbuckets Container "07bacba13cf5" is unhealthy.
ERROR: Encountered errors while bringing up the project.
原因はタイトルの通り、ベースイメージにcurl
がインストールされていないため、healthcheckが失敗するためのようです。
ちなみに、RELEASE.2023-10-25T06-33-25Z
にはcurlが入っているので、上記yamlで問題なく機能します。
bash-5.1# cat /etc/*release
NAME="Red Hat Enterprise Linux"
VERSION="9.2 (Plow)"
ID="rhel"
ID_LIKE="fedora"
VERSION_ID="9.2"
PLATFORM_ID="platform:el9"
PRETTY_NAME="Red Hat Enterprise Linux 9.2 (Plow)"
ANSI_COLOR="0;31"
LOGO="fedora-logo-icon"
CPE_NAME="cpe:/o:redhat:enterprise_linux:9::baseos"
HOME_URL="https://www.redhat.com/"
DOCUMENTATION_URL="https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/9"
BUG_REPORT_URL="https://bugzilla.redhat.com/"
REDHAT_BUGZILLA_PRODUCT="Red Hat Enterprise Linux 9"
REDHAT_BUGZILLA_PRODUCT_VERSION=9.2
REDHAT_SUPPORT_PRODUCT="Red Hat Enterprise Linux"
REDHAT_SUPPORT_PRODUCT_VERSION="9.2"
Red Hat Enterprise Linux release 9.2 (Plow)
Red Hat Enterprise Linux release 9.2 (Plow)
bash-5.1# curl
bash: curl: command not found
bash-5.1#
GitHubにも同様の質問をしている方がいました。
ベースイメージの変更が行われたようで、そのタイミングでcurl
が無くなったようです。
解決策
こちらに書かれている通り、以下のコマンドでhealthcheckをすると良いようです。
mc ready local
コンテナ内で実行した結果は以下の通りです。
bash-5.1# mc ready local
The cluster is ready
bash-5.1#
したがって、yamlのhealthcheckを以下に変更すると正常に動作しました。
healthcheck:
test: [ "CMD", "mc", "ready", "local" ]
interval: 5s
timeout: 5s
retries: 5
公式のGitHubのyamlにもこれが書かれていました。
まとめ
MinIOをDockerで構築する際のhealthcheckをネットで検索すると、多くがcurl
を利用したものがヒットしたので困惑しましたが、原因が分かり安心しました。