45 lines
1.6 KiB
Docker
45 lines
1.6 KiB
Docker
# 使用Python 3.10作为基础镜像
|
|
FROM python:3.10-slim
|
|
|
|
# 设置时区
|
|
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
|
|
# 清空所有默认源
|
|
RUN rm -rf /etc/apt/sources.list.d/* && \
|
|
rm -f /etc/apt/sources.list
|
|
|
|
# 替换为阿里云源
|
|
RUN echo "\
|
|
deb https://mirrors.aliyun.com/debian/ bookworm main non-free-firmware contrib\n\
|
|
deb-src https://mirrors.aliyun.com/debian/ bookworm main non-free-firmware contrib\n\
|
|
deb https://mirrors.aliyun.com/debian/ bookworm-updates main non-free-firmware contrib\n\
|
|
deb-src https://mirrors.aliyun.com/debian/ bookworm-updates main non-free-firmware contrib\n\
|
|
deb https://mirrors.aliyun.com/debian/ bookworm-backports main non-free-firmware contrib\n\
|
|
deb-src https://mirrors.aliyun.com/debian/ bookworm-backports main non-free-firmware contrib\n\
|
|
deb https://mirrors.aliyun.com/debian-security bookworm-security main non-free-firmware contrib\n\
|
|
deb-src https://mirrors.aliyun.com/debian-security bookworm-security main non-free-firmware contrib\n\
|
|
" > /etc/apt/sources.list
|
|
|
|
# 安装系统依赖
|
|
RUN apt-get update \
|
|
&& apt-get install -y --no-install-recommends \
|
|
build-essential \
|
|
default-libmysqlclient-dev \
|
|
pkg-config \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
# 设置工作目录
|
|
WORKDIR /app
|
|
|
|
# 复制项目文件
|
|
COPY requirements.txt .
|
|
COPY app app/
|
|
|
|
# 安装Python依赖
|
|
RUN pip install -i https://mirrors.aliyun.com/pypi/simple/ -r requirements.txt \
|
|
&& pip install uvicorn
|
|
|
|
# 暴露端口
|
|
EXPOSE 8000
|
|
|
|
# 启动命令
|
|
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000", "--reload"] |