aidress/Dockerfile
2025-03-21 21:59:44 +08:00

78 lines
2.4 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.

# 使用Python 3.10作为基础镜像
FROM python:3.10-slim
# 设置环境变量
ENV PYTHONUNBUFFERED=1
ENV PYTHONDONTWRITEBYTECODE=1
# 设置时区
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 \
curl \
nano \
&& rm -rf /var/lib/apt/lists/*
# 设置工作目录
WORKDIR /app
# 安装Python依赖先于文件复制利用缓存
COPY requirements.txt .
RUN pip install -i https://mirrors.aliyun.com/pypi/simple/ -r requirements.txt \
&& pip install -i https://mirrors.aliyun.com/pypi/simple/ uvicorn python-multipart python-dotenv
# 复制项目文件
COPY app app/
COPY *.py ./
COPY entrypoint.sh .
# 创建一个默认的.env.example文件
RUN echo "# 数据库配置\n\
DB_HOST=db\n\
DB_PORT=3306\n\
DB_USER=ai_user\n\
DB_PASSWORD=yourpassword\n\
DB_NAME=ai_dressing\n\
\n\
# 阿里云DashScope配置\n\
DASHSCOPE_API_KEY=your_dashscope_api_key\n\
\n\
# 腾讯云配置\n\
QCLOUD_SECRET_ID=your_qcloud_secret_id\n\
QCLOUD_SECRET_KEY=your_qcloud_secret_key\n\
QCLOUD_COS_REGION=ap-chengdu\n\
QCLOUD_COS_BUCKET=your-bucket-name\n\
QCLOUD_COS_DOMAIN=https://your-bucket-domain.com\n\
" > /app/.env.example
# 确保entrypoint.sh可执行
RUN chmod +x /app/entrypoint.sh
# 暴露端口
EXPOSE 8000
# 设置入口点
ENTRYPOINT ["/app/entrypoint.sh"]
# 启动命令
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000", "--log-level", "info"]