Files
test-app/Dockerfile
2025-12-11 19:41:33 +08:00

47 lines
1.5 KiB
Docker
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 使用 uv 官方镜像作为基础镜像(已包含 Python 3.14 和 uv
FROM 172.16.102.3:30648/astral-sh/uv:python3.14-bookworm
# 设置工作目录
WORKDIR /app
# 配置 apt 使用阿里云镜像源
RUN sed -i 's/httpredir.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list.d/debian.sources
# 安装系统依赖(如果需要)
RUN apt-get update && apt-get install -y --no-install-recommends \
curl \
&& rm -rf /var/lib/apt/lists/*
# 复制项目配置文件和锁定文件
COPY pyproject.toml justfile uv.lock ./
# 配置 uv 使用阿里云镜像源(通过环境变量)
ENV UV_INDEX_URL=https://mirrors.aliyun.com/pypi/simple/
# 安装 Python 依赖(使用 uv锁定版本
RUN uv sync --frozen --no-dev
# 复制应用代码和其他文件
COPY . .
# 确保 .streamlit 目录权限正确
RUN chmod -R 755 .streamlit
# 暴露 Streamlit 默认端口
EXPOSE 8000
# 设置环境变量
ENV STREAMLIT_SERVER_PORT=8000 \
STREAMLIT_SERVER_ADDRESS=0.0.0.0 \
STREAMLIT_SERVER_ENABLE_XSRF_PROTECTION=false \
STREAMLIT_SERVER_ENABLE_CORS=false \
STREAMLIT_SERVER_HEADLESS=true \
STREAMLIT_BROWSER_GATHER_USAGE_STATS=false
# 健康检查
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD curl -f http://localhost:8000/_stcore/health || exit 1
# 运行 Streamlit 应用
CMD ["uv", "run", "streamlit", "run", "app.py", "--server.port=8000", "--server.address=0.0.0.0"]