前言

使用什么系统安装的docker,一般则是用什么方式安装软件,替换源的方式,会有些许区别,如centos用yum安装,ubuntu用apt-get。

进入容器内

都是以管理员身份进入

docker exec -it -uroot jenkins bash
docker exec -itu root jenkins /bin/bash

如下图所示:
docker容器内如何更换yum源【只想换成国内源而已】

找到源文件位置并备份

cd /etc/yum.repos.d
#备份
cp CentOS-Base.repo CentOS-Base.repo.bak
cp CentOS-AppStream.repo CentOS-AppStream.repo.bak
cp CentOS-Extras.repo CentOS-Extras.repo.bak

docker容器内如何更换yum源【只想换成国内源而已】

替换为国内源

对于 CentOS 8,使用以下命令替换默认的配置

sed -e 's|^mirrorlist=|#mirrorlist=|g' \
         -e 's|^#baseurl=http://mirror.centos.org/$contentdir|baseurl=https://mirrors.ustc.edu.cn/centos|g' \
         -i.bak \
         /etc/yum.repos.d/CentOS-Base.repo \
         /etc/yum.repos.d/CentOS-Extras.repo \
         /etc/yum.repos.d/CentOS-AppStream.repo

对于 CentOS 6、7,使用以下命令替换默认配置

sed -e 's|^mirrorlist=|#mirrorlist=|g' \
         -e 's|^#baseurl=http://mirror.centos.org/centos|baseurl=https://mirrors.ustc.edu.cn/centos|g' \
         -i.bak \
         /etc/yum.repos.d/CentOS-Base.repo

更新缓存

替换之后,更新缓存。

yum makecache

docker容器内如何更换yum源【只想换成国内源而已】

参考文章:https://blog.csdn.net/qq_35995514/article/details/105988990

相关文章:

  • 2022-01-27
  • 2022-12-23
  • 2022-03-02
  • 2022-12-23
  • 2022-02-09
  • 2021-12-25
  • 2022-12-23
  • 2021-12-21
猜你喜欢
  • 2021-11-12
  • 2021-11-19
  • 2021-11-12
  • 2022-01-17
  • 2021-12-19
  • 2022-02-20
  • 2022-02-22
相关资源
相似解决方案