Browse Source

fix:dockerfile

tanjingyu 2 weeks ago
parent
commit
e371ff674d
2 changed files with 6 additions and 12 deletions
  1. 5 11
      Dockerfile
  2. 1 1
      docker-compose.yml

+ 5 - 11
Dockerfile

@@ -26,15 +26,9 @@ ENV PYTHONDONTWRITEBYTECODE=1 \
     PYTHONUNBUFFERED=1 \
     TZ=Asia/Shanghai
 
-# 安装运行时依赖(时区支持)
-RUN apt-get update && \
-    apt-get install -y --no-install-recommends \
-        tzdata \
-        curl && \
-    ln -sf /usr/share/zoneinfo/${TZ} /etc/localtime && \
-    echo "${TZ}" > /etc/timezone && \
-    apt-get clean && \
-    rm -rf /var/lib/apt/lists/*
+# 设置时区(基础镜像已自带 tzdata,无需 apt-get install)
+RUN ln -sf /usr/share/zoneinfo/${TZ} /etc/localtime && \
+    echo "${TZ}" > /etc/timezone
 
 # 创建非 root 用户
 RUN groupadd -r appuser && useradd -r -g appuser -d /app -s /sbin/nologin appuser
@@ -57,9 +51,9 @@ USER appuser
 # 暴露端口
 EXPOSE 8000
 
-# 健康检查
+# 健康检查(使用 Python 内置模块,无需安装 curl)
 HEALTHCHECK --interval=30s --timeout=10s --start-period=15s --retries=3 \
-    CMD curl -f http://localhost:8000/ || exit 1
+    CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8000/')" || exit 1
 
 # 启动命令:运行 app/main.py
 CMD ["python", "-m", "app.main"]

+ 1 - 1
docker-compose.yml

@@ -18,7 +18,7 @@ services:
       # 持久化本地存储目录
       - storage_data:/data/storage
     healthcheck:
-      test: ["CMD", "curl", "-f", "http://localhost:8000/"]
+      test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://localhost:8000/')"]
       interval: 30s
       timeout: 10s
       retries: 3