python:3.11-slim基础镜像构建
·
Dockerfile
FROM python:3.11-slim
# 1. 替换 APT 源为阿里云 Debian 12 (Bookworm) 源
RUN echo "deb http://mirrors.aliyun.com/debian/ bookworm main contrib non-free non-free-firmware" > /etc/apt/sources.list && \
echo "deb http://mirrors.aliyun.com/debian/ bookworm-updates main contrib non-free non-free-firmware" >> /etc/apt/sources.list && \
echo "deb http://mirrors.aliyun.com/debian-security/ bookworm-security main contrib non-free non-free-firmware" >> /etc/apt/sources.list && \
rm -f /etc/apt/sources.list.d/debian.sources
# 2. 配置 pip 使用阿里云源
RUN pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/ && \
pip config set global.trusted-host mirrors.aliyun.com
# 3. 升级基础工具并安装常用依赖
RUN apt-get update && \
apt-get install -y --no-install-recommends \
curl \
ca-certificates \
vim \
procps \
&& rm -rf /var/lib/apt/lists/*
# 4. 升级 pip 并预装常用 Python 包
RUN pip install --upgrade pip setuptools wheel
# 5. 设置环境变量
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PIP_NO_CACHE_DIR=1 \
LANG=C.UTF-8 \
TZ=Asia/Shanghai
# 6. 设置时区
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
WORKDIR /app
CMD ["python3"]
构建
docker build -f ./docker/python3.11-slim.dockerfile -t my-python:3.11 .
更多推荐



所有评论(0)