当前位置: 代码网 > 服务器>服务器>云虚拟主机 > Docker File创建镜像失败ERROR [3/4] RUN yum -y install vim的解决

Docker File创建镜像失败ERROR [3/4] RUN yum -y install vim的解决

2024年11月25日 云虚拟主机 我要评论
问题复现使用以下内容的docker file创建镜像:from centosmaintainer xxxxx<xxxxxxxxx@qq.com>env mypath /usr/localw

问题复现

使用以下内容的docker file创建镜像:

from centos
maintainer xxxxx<xxxxxxxxx@qq.com>

env mypath /usr/local
workdir $mypath

run yum -y install vim
run yum -y install net-tools

expose 80

cmd echo $mypath
cmd echo "============"
cmd /bin/bash

错误描述:

=> error [3/4] run yum -y install vim

------
> [3/4] run yum -y install vim:
#0 1.627 centos linux 8 - appstream 61 b/s | 38 b 00:00
#0 1.664 error: failed to download metadata for repo 'appstream': cannot prepare internal mirrorlist: no urls in mirrorlist
------
--------------------
5 | workdir $mypath
6 |
7 | >>> run yum -y install vim
8 | run yum -y install net-tools
9 |
--------------------
error: failed to solve: process "/bin/sh -c yum -y install vim" did not complete successfully: exit code: 1

解决问题方法

分析问题

> [3/4] run yum -y install vim:
#0 1.627 centos linux 8 - appstream 61 b/s | 38 b 00:00
#0 1.664 error: failed to download metadata for repo 'appstream': cannot prepare internal mirrorlist: no urls in mirrorlist

由上错误描述可知:问题是由于最新版本centos linux 8中vim软件资源下载失败导致。

解决问题

添加版本信息并修改为7即可。

from centos:7 # 添加版本
maintainer xxxxx<xxxxxxxxx@qq.com>

env mypath /usr/local
workdir $mypath

# 由于centos7停止服务,这里使用阿里云提供的centos7镜像.2024-08-04
run curl -o /etc/yum.repos.d/centos-base.repo https://mirrors.aliyun.com/repo/centos-7.repo
run yum makecache

run yum -y install vim
run yum -y install net-tools

expose 80

cmd echo $mypath
cmd echo "============"
cmd /bin/bash

完成结果

[+] building 34.8s (8/8) finished                                                          
 => [internal] load build definition from mycentos                                    0.0s
 => => transferring dockerfile: 306b                                                  0.0s
 => [internal] load .dockerignore                                                     0.0s
 => => transferring context: 2b                                                       0.0s
 => [internal] load metadata for docker.io/library/centos:7                           0.3s
 => [1/4] from docker.io/library/centos:7@sha256:9d4bcbbb213dfd745b58be38b13b996ebb5  0.0s
 => cached [2/4] workdir /usr/local                                                   0.0s
 => [3/4] run yum -y install vim                                                     29.1s
 => [4/4] run yum -y install net-tools                                                2.8s
 => exporting to image                                                                2.2s 
 => => exporting layers                                                               2.2s 
 => => writing image sha256:9a4f44d6f8c3f8cb6e515e5183feb133ff89e3bc0a8b0597b5aec81f  0.0s 
 => => naming to docker.io/library/chengxcentos:1.0                                   0.0s 

注意:docker拉取镜像默认为最新版本。

总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持代码网。

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com