Docker File创建镜像失败--ERROR [3/4] RUN yum -y install vim
docker创建镜像-vim软件资源下载失败解决方法。
问题复现:
使用以下内容的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)