imetting_backend/Dockerfile

36 lines
1.1 KiB
Docker
Raw Normal View History

2025-09-03 10:11:07 +00:00
# 使用Python 3.9.6基础镜像
FROM swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/python:3.12.9-slim
# 设置工作目录
WORKDIR /app
# 设置环境变量
ENV PYTHONPATH=/app
ENV PYTHONUNBUFFERED=1
2025-09-11 05:16:58 +00:00
# 使用阿里源
2025-10-21 09:28:52 +00:00
RUN sed -i 's/deb.debian.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apt/sources.list.d/debian.sources
RUN sed -i 's/security.debian.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apt/sources.list.d/debian.sources
2025-09-11 05:16:58 +00:00
2025-11-24 15:10:06 +00:00
# 复制依赖文件
COPY requirements-prod.txt .
# 安装系统依赖、Python依赖然后清理一个RUN命令减少层大小
2025-09-03 10:11:07 +00:00
RUN apt-get update && apt-get install -y \
gcc \
default-libmysqlclient-dev \
pkg-config \
2025-11-24 15:10:06 +00:00
&& pip install --index-url https://mirrors.aliyun.com/pypi/simple --no-cache-dir -r requirements-prod.txt \
&& apt-get purge -y gcc pkg-config \
&& apt-get autoremove -y \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
2025-09-03 10:11:07 +00:00
# 复制应用代码
COPY . .
# 暴露端口
EXPOSE 8001
# 启动命令
2025-12-11 08:48:12 +00:00
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8001"]