debian使用阿里云镜像源

下面几种方式都支持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脚本写法图例

版权声明:
作者:tianya
链接:https://tya.zone/p/150.html
来源:天涯博客
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
海报
debian使用阿里云镜像源
下面几种方式都支持8.x到11.x和12.x最新版本,即写入镜像源时自动获取系统版本,是版本自适应写法。 阿里云Debian镜像源地址:https://developer.aliyun.com/m……
<<上一篇
下一篇>>