docker:3.12.7 鏡像使用的是 debian 系統,比 ubuntu 更輕量。debian 系統內,apt 鏡像源列表位于 /etc/apt/source.list.d/debian.list(作為對比,ubuntu 的鏡像列表位于 /etc/apt/source.list,二者語法相同)。
為了方便編譯鏡像,需要修改 apt 鏡像源。借鑒修改 ubuntu 鏡像的一行命令:
RUN sed -i s:/archive.ubuntu.com:/mirrors.tuna.tsinghua.edu.cn/ubuntu:g /etc/apt/sources.list
修改 debian 鏡像源的命令是
RUN sed -i s:/deb.debian.org:/mirrors.tuna.tsinghua.edu.cn:g /etc/apt/sources.list.d/*
其中,sed -i 表示原地修改文件,s 是替換命令,會按 : 分隔,把前兩個冒號之間的文本替換成后兩個冒號之間的文件。
注:在清華園網站上,source.list 形如:
Types: deb
URIs: https://mirrors.tuna.tsinghua.edu.cn/debian
Suites: bookworm bookworm-updates bookworm-backports
Components: main contrib non-free non-free-firmware
Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg
此外,最好用 ENV PIP_INDEX_URL=https://pypi.tuna.tsinghua.edu.cn/simple 替換 pip 鏡像。不知道為什么 docker 里面 pip 巨慢。
以及,最好在開發的時候順便把 dockerfile 寫了,不然忘完了