From 69ec19e646890e7eaf4b35429e33d5d3ba7ee6b4 Mon Sep 17 00:00:00 2001 From: shangfangjian Date: Tue, 22 Sep 2026 09:59:50 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20api=20healthcheck=20=E6=94=B9=E7=94=A8?= =?UTF-8?q?=20python=20urllib(=E7=94=9F=E4=BA=A7=E9=95=9C=E5=83=8F?= =?UTF-8?q?=E6=97=A0=20curl)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit python:3.11-slim 生产镜像不含 curl,原 healthcheck 始终失败; 改为 python urllib.request,与 Dockerfile 非 root 用户兼容。 --- docker-compose.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 695181e..22db02e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -30,11 +30,11 @@ services: DATABASE_URL: postgresql+asyncpg://${POSTGRES_USER:?POSTGRES_USER 未设置}:${POSTGRES_PASSWORD:?POSTGRES_PASSWORD 未设置}@postgres:5432/${POSTGRES_DB:-football} env_file: .env healthcheck: - test: ["CMD-SHELL", "curl -sf http://localhost:8000/health/ready || exit 1"] + test: ["CMD-SHELL", "python -c \"import urllib.request; exit(0 if urllib.request.urlopen('http://localhost:8000/health/ready', timeout=5).status==200 else 1)\" || exit 1"] interval: 10s timeout: 5s retries: 3 - start_period: 10s + start_period: 15s depends_on: postgres: condition: service_healthy