zoukankan      html  css  js  c++  java
  • Docker:在Dockerfile写入多行文本覆盖内容

    场景

    由于原镜像中的/etc/apt/sources.list文件使用的源较慢,需要修改为国内的阿里云。可通过以下命令写入:

    RUN echo 'deb http://mirrors.aliyun.com/debian/ buster main non-free contrib
    
    deb http://mirrors.aliyun.com/debian-security buster/updates main
    
    deb http://mirrors.aliyun.com/debian/ buster-updates main non-free contrib
    
    deb http://mirrors.aliyun.com/debian/ buster-backports main non-free contrib
    '
    > /etc/apt/sources.list
    

    注意:

    • 这里使用单引号',所以无法使用诸如$(lsb_release -cs)的逻辑,如需使用,修改为双引号"
    • 此处无法使用$(lsb_release -cs)获取版本号,因为一般镜像没有安装software-properties-common
    • 如果想要在代码中实时获取真实的系统版本号(buster),需要使用以下命令:
      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
    
    
    deb http://mirrors.aliyun.com/debian-security $(cat /etc/os-release | grep "VERSION_CODENAME" | awk -F '=' '{print $2}')/updates main
    
    
    deb http://mirrors.aliyun.com/debian/ $(cat /etc/os-release | grep "VERSION_CODENAME" | awk -F '=' '{print $2}')-updates main non-free contrib
    
    
    deb http://mirrors.aliyun.com/debian/ $(cat /etc/os-release | grep "VERSION_CODENAME" | awk -F '=' '{print $2}')-backports main non-free contrib
    "
    > /etc/apt/sources.list
    
  • 相关阅读:
    验证信息json返回,前台接收显示无刷新。笔记
    ThinkPHP5 查询数据并处理结果
    PHP 数组和字符串互相转换实现方法
    php+jquery+ajax+json的一个最简单实例
    is_numeric 检测变量是否为数字或数字字符串
    PHP中使用cURL实现Get和Post请求的方法
    mb_substr实例
    推荐:多目标 mmoe
    多目标模型--DBMTL
    正负例优化
  • 原文地址:https://www.cnblogs.com/testopsfeng/p/15184486.html
Copyright © 2011-2022 走看看