76 lines
2.5 KiB
Docker
76 lines
2.5 KiB
Docker
# 使用国内镜像加速
|
|
FROM swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/python:3.12-slim
|
|
|
|
# 设置工作目录
|
|
WORKDIR /app
|
|
|
|
# 设置环境变量
|
|
ENV PYTHONUNBUFFERED=1 \
|
|
PYTHONDONTWRITEBYTECODE=1 \
|
|
PIP_NO_CACHE_DIR=1 \
|
|
PIP_DISABLE_PIP_VERSION_CHECK=1 \
|
|
DEBIAN_FRONTEND=noninteractive \
|
|
PIP_DEFAULT_TIMEOUT=120
|
|
|
|
# 优先尝试阿里云 Debian 镜像源,失败时自动回退官方源
|
|
RUN set -eux; \
|
|
cp /etc/apt/sources.list.d/debian.sources /tmp/debian.sources.bak; \
|
|
sed -i 's|http://deb.debian.org|http://mirrors.aliyun.com|g' /etc/apt/sources.list.d/debian.sources; \
|
|
sed -i 's|http://security.debian.org|http://mirrors.aliyun.com|g' /etc/apt/sources.list.d/debian.sources; \
|
|
dpkg --configure -a || true; \
|
|
apt-get -f install -y || true; \
|
|
if ! apt-get update; then \
|
|
cp /tmp/debian.sources.bak /etc/apt/sources.list.d/debian.sources; \
|
|
dpkg --configure -a || true; \
|
|
apt-get -f install -y || true; \
|
|
apt-get update; \
|
|
fi; \
|
|
if ! apt-get install -y --no-install-recommends \
|
|
libpango-1.0-0 \
|
|
libpangoft2-1.0-0 \
|
|
libpangocairo-1.0-0 \
|
|
libgdk-pixbuf-2.0-0 \
|
|
libcairo2 \
|
|
shared-mime-info \
|
|
fontconfig \
|
|
fonts-dejavu-core \
|
|
fonts-wqy-microhei; then \
|
|
cp /tmp/debian.sources.bak /etc/apt/sources.list.d/debian.sources; \
|
|
dpkg --configure -a || true; \
|
|
apt-get -f install -y || true; \
|
|
apt-get update; \
|
|
apt-get install -y --no-install-recommends \
|
|
libpango-1.0-0 \
|
|
libpangoft2-1.0-0 \
|
|
libpangocairo-1.0-0 \
|
|
libgdk-pixbuf-2.0-0 \
|
|
libcairo2 \
|
|
shared-mime-info \
|
|
fontconfig \
|
|
fonts-dejavu-core \
|
|
fonts-wqy-microhei; \
|
|
fi; \
|
|
rm -rf /var/lib/apt/lists/*
|
|
|
|
# 复制依赖文件
|
|
COPY requirements.txt .
|
|
|
|
# 升级打包工具,减少 PEP517/源码构建失败
|
|
RUN pip install --no-cache-dir --upgrade pip setuptools wheel -i https://pypi.tuna.tsinghua.edu.cn/simple
|
|
|
|
# 安装 Python 依赖
|
|
RUN pip install --no-cache-dir -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple || \
|
|
pip install --no-cache-dir -r requirements.txt -i https://pypi.org/simple
|
|
|
|
# 复制项目文件
|
|
COPY . .
|
|
|
|
# 创建必要的目录
|
|
RUN mkdir -p /data/nex_docus_store/projects /data/nex_docus_store/temp logs
|
|
|
|
# 暴露端口
|
|
EXPOSE 8000
|
|
|
|
# 启动命令
|
|
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
|