下面几种方式都支持8.x到11.x和12.x最新版本,即写入镜像源时自动获取系统版本,是版本自适应写法。
阿里云Debian镜像源地址:https://developer.aliyun.com/mirror/debian
shell中版本自适应写法(支持所有版本)
先备份再创建新的sources.list文件
mv /etc/apt/sources.list{,.backup`date +%Y%m%d%H%M%S`} \ && cat > /etc/apt/sources.list <<EOF deb https://mirrors.aliyun.com/debian/ $(cat /etc/os-release | grep ‘VERSION_CODENAME’ | awk -F ‘=’ ‘{print $2}’) main non-free contrib deb-src https://mirrors.aliyun.com/debian/ $(cat /etc/os-release | grep ‘VERSION_CODENAME’ | awk -F ‘=’ ‘{print $2}’) main non-free contrib deb https://mirrors.aliyun.com/debian-security/ $(cat /etc/os-release | grep ‘VERSION_CODENAME’ | awk -F ‘=’ ‘{print $2}’)-security main deb-src https://mirrors.aliyun.com/debian-security/ $(cat /etc/os-release | grep ‘VERSION_CODENAME’ | awk -F ‘=’ ‘{print $2}’)-security main deb https://mirrors.aliyun.com/debian/ $(cat /etc/os-release | grep ‘VERSION_CODENAME’ | awk -F ‘=’ ‘{print $2}’)-updates main non-free contrib deb-src https://mirrors.aliyun.com/debian/ $(cat /etc/os-release | grep ‘VERSION_CODENAME’ | awk -F ‘=’ ‘{print $2}’)-updates main non-free contrib deb https://mirrors.aliyun.com/debian/ $(cat /etc/os-release | grep ‘VERSION_CODENAME’ | awk -F ‘=’ ‘{print $2}’)-backports main non-free contrib deb-src https://mirrors.aliyun.com/debian/ $(cat /etc/os-release | grep ‘VERSION_CODENAME’ | awk -F ‘=’ ‘{print $2}’)-backports main non-free contrib EOF
Dockerfile中用法示例
以下是RUN指令写法示例
RUN echo “deb https://mirrors.aliyun.com/debian/ $(cat /etc/os-release | grep ‘VERSION_CODENAME’ | awk -F ‘=’ ‘{print $2}’) main non-free contrib \ \ndeb-src https://mirrors.aliyun.com/debian/ $(cat /etc/os-release | grep ‘VERSION_CODENAME’ | awk -F ‘=’ ‘{print $2}’) main non-free contrib \ \ndeb https://mirrors.aliyun.com/debian-security/ $(cat /etc/os-release | grep ‘VERSION_CODENAME’ | awk -F ‘=’ ‘{print $2}’)-security main \ \ndeb-src https://mirrors.aliyun.com/debian-security/ $(cat /etc/os-release | grep ‘VERSION_CODENAME’ | awk -F ‘=’ ‘{print $2}’)-security main \ \ndeb https://mirrors.aliyun.com/debian/ $(cat /etc/os-release | grep ‘VERSION_CODENAME’ | awk -F ‘=’ ‘{print $2}’)-updates main non-free contrib \ \ndeb-src https://mirrors.aliyun.com/debian/ $(cat /etc/os-release | grep ‘VERSION_CODENAME’ | awk -F ‘=’ ‘{print $2}’)-updates main non-free contrib \ \ndeb https://mirrors.aliyun.com/debian/ $(cat /etc/os-release | grep ‘VERSION_CODENAME’ | awk -F ‘=’ ‘{print $2}’)-backports main non-free contrib \ \ndeb-src https://mirrors.aliyun.com/debian/ $(cat /etc/os-release | grep ‘VERSION_CODENAME’ | awk -F ‘=’ ‘{print $2}’)-backports main non-free contrib” \ > /etc/apt/sources.list
一键生成dockerfile脚本示例
使用cat命令一键生成Dockerfile文件 cat > Dockerfile <<EOF FROM debian:latest USER root RUN cat /etc/os-release | grep VERSION_CODENAME | awk -F = ‘{print \$2}’ RUN echo “deb http://mirrors.aliyun.com/debian/ \$(cat /etc/os-release | grep VERSION_CODENAME | awk -F = ‘{print \$2}’) main non-free contrib” RUN echo “deb https://mirrors.aliyun.com/debian/ \$(cat /etc/os-release | grep ‘VERSION_CODENAME’ | awk -F ‘=’ ‘{print \$2}’) main non-free contrib \ \ndeb-src https://mirrors.aliyun.com/debian/ \$(cat /etc/os-release | grep ‘VERSION_CODENAME’ | awk -F ‘=’ ‘{print \$2}’) main non-free contrib \ \ndeb https://mirrors.aliyun.com/debian-security/ \$(cat /etc/os-release | grep ‘VERSION_CODENAME’ | awk -F ‘=’ ‘{print \$2}’)-security main \ \ndeb-src https://mirrors.aliyun.com/debian-security/ \$(cat /etc/os-release | grep ‘VERSION_CODENAME’ | awk -F ‘=’ ‘{print \$2}’)-security main \ \ndeb https://mirrors.aliyun.com/debian/ \$(cat /etc/os-release | grep ‘VERSION_CODENAME’ | awk -F ‘=’ ‘{print \$2}’)-updates main non-free contrib \ \ndeb-src https://mirrors.aliyun.com/debian/ \$(cat /etc/os-release | grep ‘VERSION_CODENAME’ | awk -F ‘=’ ‘{print \$2}’)-updates main non-free contrib \ \ndeb https://mirrors.aliyun.com/debian/ \$(cat /etc/os-release | grep ‘VERSION_CODENAME’ | awk -F ‘=’ ‘{print \$2}’)-backports main non-free contrib \ \ndeb-src https://mirrors.aliyun.com/debian/ \$(cat /etc/os-release | grep ‘VERSION_CODENAME’ | awk -F ‘=’ ‘{print \$2}’)-backports main non-free contrib” \ > /etc/apt/sources.list RUN cat /etc/apt/sources.list # 安装curl RUN apt-get update \ && apt-get install -y curl \ && rm -rf /var/lib/apt/lists/* USER rootless EOF
一键生成Dockerfile脚本写法图例
参考链接
- 官方主页: http://www.debian.org/
- 邮件列表: http://www.debian.org/support#mail_lists
- Wiki: http://wiki.debian.org/
- 文档: http://www.debian.org/doc/
- 镜像列表: http://www.debian.org/mirror/list
- 小瑞Blog-轻言轻愿: https://blog.tinyrui.com/2023/11/42/