缩小Docker运行镜像体积

This commit is contained in:
2026-05-06 09:39:53 +08:00
parent edc7d970a8
commit 38c8e8918d
2 changed files with 16 additions and 18 deletions
+1
View File
@@ -8,6 +8,7 @@
- 移除代码中的默认 iDRAC 地址、账号和密码,改为必须通过环境变量配置。
- 增加 `.env.example``.dockerignore` 和 MIT License。
- 清理 Python 缓存文件,避免将运行产物提交到仓库。
- Docker 运行镜像切换到 Alpine,只安装 `python3``ipmitool` 和时区数据,降低镜像体积。
## Previous Improvements
+15 -18
View File
@@ -1,25 +1,22 @@
FROM ubuntu:22.04
FROM alpine:3.20
LABEL maintainer="lkddi"
# 安装依赖并设置时区
RUN apt update && apt install -y \
ipmitool \
python3 \
python3-pip \
&& rm -rf /var/lib/apt/lists/* \
&& ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& echo 'Asia/Shanghai' > /etc/timezone
ENV TZ=Asia/Shanghai \
PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1
# 复制应用文件
COPY . /dell-fans-controller
# 安装运行所需的最小依赖并设置容器时区
RUN apk add --no-cache \
ipmitool \
python3 \
tzdata \
&& cp /usr/share/zoneinfo/${TZ} /etc/localtime \
&& echo "${TZ}" > /etc/timezone
# 只复制运行所需源码,避免文档和仓库元数据进入镜像
WORKDIR /dell-fans-controller
# 如果有requirements.txt则安装Python依赖
# COPY requirements.txt .
# RUN pip3 install --no-cache-dir -r requirements.txt
# 暴露可能需要的端口(虽然这个应用不需要)
# EXPOSE 80
COPY controller ./controller
COPY start.py ./
# 设置启动命令
CMD ["python3", "start.py"]