fix docker file

This commit is contained in:
Kevin
2026-05-25 11:39:38 +08:00
parent 07979bfb09
commit 10d9e13f14
2 changed files with 9 additions and 6 deletions

View File

@@ -24,17 +24,20 @@ WORKDIR /app
COPY pyproject.toml uv.lock ./
RUN uv sync --frozen --no-dev --no-install-project
# 复制应用代码
# 复制应用代码并在镜像内安装项目(避免运行时 uv run 重新 sync 拉 dev 依赖)
COPY . .
RUN uv sync --frozen --no-dev
# 非 root 用户
RUN useradd -m -u 1000 appuser && chown -R appuser:appuser /app
USER appuser
ENV PATH="/app/.venv/bin:$PATH"
EXPOSE 8000
HEALTHCHECK --interval=15s --timeout=5s --start-period=120s --retries=6 \
CMD python -c "import http.client; conn = http.client.HTTPConnection('localhost', 8000); conn.request('GET', '/health'); r = conn.getresponse(); exit(0 if r.status == 200 else 1)" || exit 1
# Alembic 迁移放到 FastAPI startup带重试与日志入口仅启动 web 进程。
CMD ["sh", "-c", "uv run uvicorn main:app --host 0.0.0.0 --port 8000"]
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]