crypto.ai/Dockerfile
2025-04-29 21:01:52 +08:00

64 lines
1.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.

FROM python:3.10-slim as builder
# 安装系统依赖
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
gcc \
g++ \
libc6-dev \
python3-dev \
git \
curl \
&& rm -rf /var/lib/apt/lists/*
# 设置工作目录
WORKDIR /build
# 复制依赖文件
COPY requirements.txt .
# 安装依赖
RUN pip install --upgrade pip && \
pip install wheel setuptools && \
pip wheel --wheel-dir=/build/wheels -r requirements.txt
# 第二阶段:最终镜像
FROM python:3.10-slim
# 安装运行时依赖
RUN apt-get update && apt-get install -y --no-install-recommends \
libgomp1 \
&& rm -rf /var/lib/apt/lists/*
# 设置工作目录
WORKDIR /app
# 从构建阶段复制预构建的wheel文件
COPY --from=builder /build/wheels /wheels
# 安装预构建的wheel
RUN pip install --upgrade pip && \
pip install --no-index --find-links=/wheels /wheels/* && \
rm -rf /wheels
# 复制应用代码
COPY . .
# 设置Python路径
ENV PYTHONPATH=/app
# 创建数据和日志目录
RUN mkdir -p /app/cryptoai/data /app/cryptoai/logs
# 复制API启动脚本
COPY run_api.py ./
# 暴露API端口
EXPOSE 8000
# 启动命令行使用CMD方便docker-compose覆盖
CMD ["python", "run.py"]
# API服务启动方式
# docker run -p 8000:8000 -e "COMMAND=api" your-image-name
# 或者在docker-compose.yml中设置command: python run_api.py