imetting/backend/Dockerfile

37 lines
1.1 KiB
Docker
Raw Normal View History

# 使用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
# 使用阿里源
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
# 复制依赖文件
COPY requirements.txt .
# 安装系统依赖、Python依赖然后清理一个RUN命令减少层大小
RUN apt-get update && apt-get install -y \
gcc \
2026-01-19 11:40:39 +00:00
curl \
default-libmysqlclient-dev \
pkg-config \
&& pip install --index-url https://mirrors.aliyun.com/pypi/simple --no-cache-dir -r requirements.txt \
&& apt-get purge -y gcc pkg-config \
&& apt-get autoremove -y \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# 复制应用代码
COPY . .
# 暴露端口
EXPOSE 8000
# 启动命令
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]