系统相关
首页 > 系统相关> > docker使用centos:latest镜像执行yum install失败

docker使用centos:latest镜像执行yum install失败

作者:互联网

现象

[root@torres nginx]# docker build -t torres/nginx:v1 .
Sending build context to Docker daemon  1.044MB
Error response from daemon: dockerfile parse error line 9: unknown instruction: &&
[root@torres nginx]# docker build -t torres/nginx:v1 .
Sending build context to Docker daemon  1.044MB
Step 1/10 : FROM centos
latest: Pulling from library/centos
a1d0c7532777: Pull complete 
Digest: sha256:a27fd8080b517143cbbbab9dfb7c8571c40d67d534bbdee55bd6c473f432b177
Status: Downloaded newer image for centos:latest
 ---> 5d0da3dc9764
Step 2/10 : MAINTAINER Torres
 ---> Running in 28854ab3cdc0
Removing intermediate container 28854ab3cdc0
 ---> ab41eef11122
Step 3/10 : RUN yum install -y gcc make pcre-devel zlib-devel tar zlib
 ---> Running in b8e8a1130c60
CentOS Linux 8 - AppStream                      109  B/s |  38  B     00:00    
Error: Failed to download metadata for repo 'appstream': Cannot prepare internal mirrorlist: No URLs in mirrorlist
The command '/bin/sh -c yum install -y gcc make pcre-devel zlib-devel tar zlib' returned a non-zero code: 1

原因

Centos8于2021年年底停止了服务,大家再在使用yum源安装时候,出现下面错误“错误:Failed to download metadata for repo ‘AppStream’: Cannot prepare internal mirrorlist: No URLs in mirrorlist”

解决方案

#进入容器
[root@torres nginx]# docker run -it centos
#修改yum源
[root@199e67dbd163 /]# cd etc/yum.repos.d/
[root@199e67dbd163 yum.repos.d]# sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
[root@199e67dbd163 yum.repos.d]# sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*
#安装wget
[root@199e67dbd163 yum.repos.d]# yum install -y wget
#安装阿里云源
[root@199e67dbd163 yum.repos.d]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
#制作镜像
[root@torres nginx]# docker commit -m "update yum.repo.d" -a "torres" 199e67dbd163 centos-ali:v1
sha256:e8a23e7efc371bd68be41aa5c4bbc971dcbb7ade8240c356eff5a3d0a4b873bb
[root@torres nginx]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED         SIZE
centos-ali   v1        e8a23e7efc37   7 seconds ago   299MB
centos       latest    5d0da3dc9764   8 months ago    231MB

标签:torres,centos,repos,nginx,yum,install,root
来源: https://www.cnblogs.com/Torres-tao/p/16355674.html