百度360必应搜狗淘宝本站头条
当前位置:网站首页 > IT知识 > 正文

# docker 构建centos 镜像出现错误 `RUN yum install -y vim` 报错

liuian 2025-01-18 21:55 13 浏览

#服务器虚拟化的好处你知道吗?#

# docker 构建centos 镜像出现错误ERROR: failed to solve: process "/bin/sh -c yum install -y vim" did not complete successfully: 解决方法



## 一、在使用docker 构建centos 镜像,如果 执行 ` docker build -f ./centos_dockerfile -t centos_usr:v1 .` 时 `RUN yum install -y vim` 报错


错误信息如下 :

Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=container error was

curl#6 - "Could not resolve host: mirrorlist.centos.org; Unknown error"

......

yum-config-manager --save --setopt=<repoid>.skip_if_unavailable=true

Cannot find a valid baseurl for repo: base/7/x86_64

......

ERROR: failed to solve: process "/bin/sh -c yum install -y vim" did not complete successfully: exit code: 1


如下图:







## 二、解决方法:


可以尝试以下方法,进行逐一排除(任何一项执行后,如果构建正常,就无须进行下一项)。



### 1、修改编辑 centos_dockerfile 文件:vim centos_dockerfile


```bash

FROM centos:7

MAINTAINER dzs168


RUN cd /etc/yum.repos.d/ \

&& sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-* \

&& sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-* \

&& yum install -y vim


CMD /bin/bash


WORKDIR /usr

```


### 2、配置 yum 源 vim /etc/yum.repos.d/CentOS-Base.repo


```bash

# 更改 yum 源


# CentOS-Base.repo

#

# The mirror system uses the connecting IP address of the client and the

# update status of each mirror to pick mirrors that are updated to and

# geographically close to the client. You should use this for CentOS updates

# unless you are manually picking other mirrors.

#

# If the mirrorlist= does not work for you, as a fall back you can try the

# remarked out baseurl= line instead.


[base]

name=CentOS-$releasever - Base - mirrors.aliyun.com

failovermethod=priority

baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/

http://mirrors.aliyuncs.com/centos/$releasever/os/$basearch/

http://mirrors.cloud.aliyuncs.com/centos/$releasever/os/$basearch/

gpgcheck=1

gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7


#released updates

[updates]

name=CentOS-$releasever - Updates - mirrors.aliyun.com

failovermethod=priority

baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/

http://mirrors.aliyuncs.com/centos/$releasever/updates/$basearch/

http://mirrors.cloud.aliyuncs.com/centos/$releasever/updates/$basearch/

gpgcheck=1

gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7


#additional packages that may be useful

[extras]

name=CentOS-$releasever - Extras - mirrors.aliyun.com

failovermethod=priority

baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/

http://mirrors.aliyuncs.com/centos/$releasever/extras/$basearch/

http://mirrors.cloud.aliyuncs.com/centos/$releasever/extras/$basearch/

gpgcheck=1

gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7


#additional packages that extend functionality of existing packages

[centosplus]

name=CentOS-$releasever - Plus - mirrors.aliyun.com

failovermethod=priority

baseurl=http://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/

http://mirrors.aliyuncs.com/centos/$releasever/centosplus/$basearch/

http://mirrors.cloud.aliyuncs.com/centos/$releasever/centosplus/$basearch/

gpgcheck=1

enabled=0

gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7


#contrib - packages by Centos Users

[contrib]

name=CentOS-$releasever - Contrib - mirrors.aliyun.com

failovermethod=priority

baseurl=http://mirrors.aliyun.com/centos/$releasever/contrib/$basearch/

http://mirrors.aliyuncs.com/centos/$releasever/contrib/$basearch/

http://mirrors.cloud.aliyuncs.com/centos/$releasever/contrib/$basearch/

gpgcheck=1

enabled=0

gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

```


### 3、启用仓库配置


```shell

yum-config-manager --enable base

```



### 4、清理缓存,重建缓存


```bash

yum clean all

yum makecache

```


### 5、配置网卡,添加 DNS 服务器:vim /etc/sysconfig/network-scripts/ifcfg-enp0s3


```bash

TYPE=Ethernet

PROXY_METHOD=none

BROWSER_ONLY=no

# BOOTPROTO=dhcp

BOOTPROTO=static

IPADDR=192.168.43.216

NETMASK=255.255.255.0

GATEWAY=192.168.43.1

DNS1=8.8.8.8

DNS2=114.114.114.114

DEFROUTE=yes

IPV4_FAILURE_FATAL=no

IPV6INIT=yes

IPV6_AUTOCONF=yes

IPV6_DEFROUTE=yes

IPV6_FAILURE_FATAL=no

IPV6_ADDR_GEN_MODE=stable-privacy

NAME=enp0s3

UUID=43f2469a-7ff2-418f-ac9a-3bc5a3f14d46

DEVICE=enp0s3

ONBOOT=yes

```


### 6、重启网卡


```bash

systemctl restart network


# 或者

service network restart

```


### 7、配置 docker 镜像加速器 vim /etc/docker/daemon.json


```bash

# 配置内容如下:


{

"registry-mirrors": ["https://5y3wa0zw.mirror.aliyuncs.com",

"http://hub-mirror.c.163.com",

"https://docker.m.daocloud.io/",

"https://huecker.io/",

"https://dockerhub.timeweb.cloud",

"https://noohub.ru/",

"https://dockerproxy.com",

"https://docker.mirrors.ustc.edu.cn",

"https://docker.nju.edu.cn",

"https://xx4bwyg2.mirror.aliyuncs.com",

"http://f1361db2.m.daocloud.io",

"https://registry.docker-cn.com",

"https://docker.mirrors.ustc.edu.cn"

]

}


# 重新加载配置文件

systemctl daemon-reload


# 重启docker

systemctl restart docker

```


### 8、在当前目录(注意命令后面的 `.`),重新通过dockerfile构建镜像


```bash

docker build -f ./centos_dockerfile -t centos_usr:v1 .

```











相关推荐

Flutter——输入部件

上一节介绍了文本部件,用于显示文本。但是在我们进行日常软件开发过程中,经常是需要获取用户键入的内容,比如用户名、密码、性别、喜好等等。Flutter提供了丰富的部件来处理用户输入,本节将主要介绍以下...

flutter系列之:做一个图像滤镜

简介很多时候,我们需要一些特效功能,比如给图片做个滤镜什么的,如果是h5页面,那么我们可以很容易的通过css滤镜来实现这个功能。那么如果在flutter中,如果要实现这样的滤镜功能应该怎么处理呢?一起...

免费好用还高级!3个必须知道的设计网站,让你的PPT好看10倍

哈喽,大家早上好鸭~好久不见,我是三石,今天我又来进行PPT技巧分享啦~诶,这不前几天编辑部的萌萌就来找我约稿,说小叶子们对于神器网站的呼声很高,问我能不能写一篇文章汇总一下,我二话没说就答应了。常言...

flutter软件开发笔记08-容器使用方法

在Flutter3中,容器组件是用于布局、装饰或约束子组件的核心部件,能让程序更加美观,如何学习呢,能快速的应用起来,下面通过例子,来快速理解各种容器组件的使用方法。一程序界面二代码实现imp...

Tauri:下一代桌面应用开发框架?

大厂技术坚持周更精选好文本文为来自教育-智能学习-前端团队成员的文章,已授权ELab发布。智能学习前端团队自创立以来,团队专注于打破大众对教育的刻板印象,突破固有的教学思维,攻破各类...

Google移动开发平台Flutter发布 iOS和Android开发者神器

在昨晚的FlutterLive2018上,Google宣布Flutter1.0正式发布。这是一个基于Dart的移动开发平台,旨在帮助开发者在iOS和Android两个平台上...

Flutter如何内存优化

Flutter是一种流行的跨平台移动应用程序开发框架,它提供了一种高效的方式来构建美观、快速、可靠的应用程序。然而,随着应用程序规模的增加,内存管理成为了一个重要的问题。本文将探讨如何优化Flutte...

阿里卖家 Flutter for Web 工程实践

作者:马坤乐(坤吾)Flutter自2015年初次亮相以来,经过了多年的发展已经相当成熟,在阿里、美团、拼多多等互联网公司都有广泛的应用。在ICBU阿里卖家上90+%的新业务使用Flu...

Flutter——按钮

上一节介绍了输入组件,让我们了解了输入框、单选、多选、进度条等部件。为了响应用户的点击或触摸操作,就需要学习一种新的部件-按钮。Flutter中有多种类型的按钮,用于响应用户的点击或触摸操作。接下来...

Flutter vs React Native 性能测试结果

FluttervsReactNative性能测试结果:谁才是王者?大家好,我是猫哥。今天会去讲一下Flutter和ReactNative的性能比较的情况。首先说一下ReactNative猫哥...

定位Flutter内存问题很难么?

内存水位升高导致的稳定性问题严重影响app用户体验,所以开发者们非常关注Flutter的内存表现。随着Flutter业务越来越多,闲鱼也面临着oom导致的crash率提升的问题,下面我们结合项目中实际...

超详解析Flutter渲染引擎|业务想创新,不了解底层原理怎么行?

作者|万红波(远湖)出品|阿里巴巴新零售淘系技术部前言Flutter作为一个跨平台的应用框架,诞生之后,就被高度关注。它通过自绘UI,解决了之前RN和weex方案难以解决的多端一致性...

flutter软件开发笔记25-内置组件总结

以下是Flutter内置的核心UI组件分类及常用组件列表,方便你系统化学习和掌握:1.基础组件组件名说明Text显示文本,支持样式、换行和富文本(TextSpan)Icon显示Materi...

Flutter CarouselView 3.24版本的一个新组件

Flutter3.24带来了几个令人兴奋的新功能,其中最引人注目的是CarouselView小部件。这个小部件允许开发人员创建可滚动的、动态的项目列表,这些列表可以在进入和退出视图时调整大小,这对于...

详解Flutter如何用思源宋体炫出你的UI

如何实现使用思源宋体字体样式。首先,让我们来了解一下什么是资源素材管理。简单来说,它就是为了方便我们管理各种资源文件,比如图片、字体、音频等。在Flutter中,我们可以使用pubspec.yam...