Skip to content

Commit

Permalink
Update Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
olixu authored Apr 14, 2024
1 parent d507612 commit 744cbfa
Showing 1 changed file with 14 additions and 27 deletions.
41 changes: 14 additions & 27 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# 使用Alpine Linux Python镜像
FROM python:3-alpine
# 使用Debian的Python镜像
FROM python:3-slim

# 设置作者或维护者信息(可选)
LABEL maintainer="your_email@example.com"
Expand All @@ -8,37 +8,24 @@ LABEL maintainer="your_email@example.com"
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1

# 更新apk索引,安装git、libstdc++(修复libstdc++.so.6缺失问题)、tzdata(包含时区数据),
# 以及编译相关的包
RUN apk update \
&& apk add --no-cache git libstdc++ tzdata \
&& apk add --no-cache --virtual .build-deps \
g++ \
gcc \
libxslt-dev \
libffi-dev \
openssl-dev \
musl-dev \
make \
cmake

# 设置时区为上海(北京时间)
ENV TZ=Asia/Shanghai
# 使用apt安装必要的依赖,然后清理缓存以减小镜像大小
RUN apt-get update \
&& apt-get install -y --no-install-recommends git \
&& apt-get install -y --no-install-recommends g++ gcc libxslt-dev libffi-dev openssl-dev make cmake \
&& echo "Asia/Shanghai" > /etc/timezone \
&& dpkg-reconfigure -f noninteractive tzdata \
&& pip install --upgrade pip \
&& pip install --no-cache-dir -r requirements.txt \
# 清理不再需要的包和缓存
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

# 克隆项目仓库
RUN mkdir /app
WORKDIR /app
RUN git clone https://github.com/olixu/stocktrend.git .

# 安装Python依赖
# requirements文件应该位于仓库的根目录
RUN pip install --upgrade pip \
&& pip install --no-cache-dir -r requirements.txt

# 清理不需要的包和缓存,减小镜像体积
# 注意这里我们没有删除libstdc++,因为它是运行时依赖
RUN apk del .build-deps

# 暴露端口(假设你的应用使用的是8080端口)
EXPOSE 8080

Expand Down

0 comments on commit 744cbfa

Please sign in to comment.