场景
使用自定义Dockerfile构建Redis镜像时,出现了异常
Dockerfile文件内容如下:
FROM centos
RUN ["yum","install","-y","gcc","gcc-c++","net-tools","make"]
WORKDIR /docker/docker-redis
ADD redis-4.0.14.tar.gz .
WORKDIR /docker/docker-redis/redis-4.0.14/src
RUN make && make install
WORKDIR /docker/docker-redis/redis-4.0.14
ADD redis-7000.conf .
EXPOSE 7000
CMD ["redis-server","redis-7000.conf"]
遇到的问题
[root@localhost docker-redis]# docker build -t forlan.com/docker-redis .
[+] Building 2.2s (6/12) docker:default=> [internal] load build definition from Dockerfile 0.0s=> => transferring dockerfile: 416B 0.0s=> [internal] load .dockerignore 0.1s=> => transferring context: 2B 0.0s=> [internal] load metadata for docker.io/library/centos:latest 0.3s=> CACHED [1/8] FROM docker.io/library/centos@sha256:a27fd8080b517143cbbbab9dfb7c8571c40d67d534bbdee55bd6c473f432b177 0.0s=> [internal] load build context 0.0s=> => transferring context: 190B 0.0s=> ERROR [2/8] RUN ["yum" , "install" , "-y" ,"gcc","gcc-c++","net-tools","make"] 1.7s
------> [2/8] RUN ["yum" , "install" , "-y" ,"gcc","gcc-c++","net-tools","make"]:
1.603 Error: Failed to download metadata for repo 'appstream': Cannot prepare internal mirrorlist: No URLs in mirrorlist
1.603 CentOS Linux 8 - AppStream 57 B/s | 38 B 00:00
------
Dockerfile:2
--------------------1 | FROM centos2 | >>> RUN ["yum" , "install" , "-y" ,"gcc","gcc-c++","net-tools","make"]3 | WORKDIR /docker/docker-redis4 | ADD redis-4.0.14.tar.gz .
--------------------
ERROR: failed to solve: process "yum install -y gcc gcc-c++ net-tools make" did not complete successfully: exit code: 1
解决
在2020 年 12 月 8 号,CentOS 官方宣布了停止维护 CentOS Linux 的计划,并推出了 CentOS Stream 项目,CentOS Linux 8 作为 RHEL 8 的复刻版本,生命周期缩短,于 2021 年 12 月 31 日停止更新并停止维护(EOL)
1、增加内容
主要增加以下内容,修改yum包管理器的源配置
RUN cd /etc/yum.repos.d/
RUN sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
RUN sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*
RUN yum update -y
完整内容如下:
FROM centos
RUN cd /etc/yum.repos.d/
RUN sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
RUN sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*
RUN yum update -y
RUN ["yum" , "install" , "-y" ,"gcc","gcc-c++","net-tools","make"]
WORKDIR /docker/docker-redis
ADD redis-4.0.14.tar.gz .
WORKDIR /docker/docker-redis/redis-4.0.14/src
RUN make && make install
WORKDIR /docker/docker-redis/redis-4.0.14
ADD redis-7000.conf .
EXPOSE 7000
CMD ["redis-server","redis-7000.conf"]
2、调整内容
FROM centos-》FROM centos:centos7