问题复现
使用以下内容的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拉取镜像默认为最新版本。
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持代码网。
发表评论