aim/docker/base/Dockerfile.ubuntu2004.pytho...

48 lines
1.9 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.9 + 清华源 ----------
FROM ccr.ccs.tencentyun.com/somunslotus/ubuntu:20.04
ENV DEBIAN_FRONTEND=noninteractive
# 切换为阿里云源HTTP
RUN sed -i 's|http://archive.ubuntu.com/ubuntu/|http://mirrors.aliyun.com/ubuntu/|g' /etc/apt/sources.list && \
sed -i 's|http://security.ubuntu.com/ubuntu/|http://mirrors.aliyun.com/ubuntu/|g' /etc/apt/sources.list && \
apt-get clean && apt-get update
# 先移除系统自带的 Python 3.8(如果存在)
RUN apt-get remove -y python3.8 python3.8-minimal python3.8-venv python3.8-distutils 2>/dev/null || true
# 安装 Python 3.9 及相关开发包
RUN apt-get install -y --no-install-recommends \
software-properties-common && \
add-apt-repository ppa:deadsnakes/ppa -y && \
apt-get update && \
apt-get install -y --no-install-recommends \
python3.9 python3.9-venv python3.9-distutils python3.9-dev python3.9-full \
curl vim ca-certificates git build-essential && \
# 清理不再需要的包
apt-get remove -y software-properties-common && \
apt-get autoremove -y && \
apt-get clean && rm -rf /var/lib/apt/lists/*
# 设置 Python 3.9 为默认版本
RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.9 1 && \
update-alternatives --install /usr/bin/python python /usr/bin/python3.9 1 && \
# 确保 pip 指向正确的 Python 版本
curl -sS https://bootstrap.pypa.io/get-pip.py | python3.9 && \
ln -sf /usr/bin/python3.9 /usr/bin/python
# 配置 pip 使用清华源
RUN pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
# 验证 Python 与 pip 版本
RUN python --version && python3 --version && pip --version
# 验证所有 Python 相关命令都指向 3.9
RUN echo "Python commands check:" && \
ls -la /usr/bin/python* && \
echo "Python3 version:" && \
python3 -V && \
echo "Python version:" && \
python -V && \
echo "pip3 version:" && \
pip3 -V