- 原
Dockerfile
内容如下:
FROM tomcat:8.5-jre8
# 安装 ffmpeg
RUN apt-get update
RUN apt-get install -y --no-install-recommends ffmpeg
# 拷 war 包
COPY bear-api.war webapps/ROOT.war
EXPOSE 8080
- 执行时发现
apt-get update
下载非常慢,需要更换国内的apt
镜像源 - 在
Dockerfile
中添加RUN cat /etc/apt/sources.list
,用于查看当前的镜像源,Dockerfile
如下:
FROM tomcat:8.5-jre8
# 安装 ffmpeg
RUN cat /etc/apt/sources.list
RUN apt-get update
RUN apt-get install -y --no-install-recommends ffmpeg
# 拷 war 包
COPY bear-api.war webapps/ROOT.war
EXPOSE 8080
- 执行结果如下:
Step 5/15 : RUN cat /etc/apt/sources.list
---> Running in 154db26bbb51
# deb http://snapshot.debian.org/archive/debian/20211220T000000Z bullseye main
deb http://deb.debian.org/debian bullseye main
# deb http://snapshot.debian.org/archive/debian-security/20211220T000000Z bullseye-security main
deb http://security.debian.org/debian-security bullseye-security main
# deb http://snapshot.debian.org/archive/debian/20211220T000000Z bullseye-updates main
deb http://deb.debian.org/debian bullseye-updates main
- 通过执行结果发现当前镜像源是
security.debian.org
,在Dockerfile
中添加RUN sed -i s@/deb.debian.org/@/mirrors.aliyun.com/@g /etc/apt/sources.list
,替换为阿里镜像源,修改Dockerfile
如下:
FROM tomcat:8.5-jre8
# 安装 ffmpeg
RUN sed -i s@/deb.debian.org/@/mirrors.aliyun.com/@g /etc/apt/sources.list
RUN cat /etc/apt/sources.list
RUN apt-get clean
RUN apt-get update
RUN apt-get install -y --no-install-recommends ffmpeg
# 拷 war 包
COPY bear-api.war webapps/ROOT.war
EXPOSE 8080
- 再执行可以看到已经更换为阿里镜像,下载速度变快
Step 3/8 : RUN cat /etc/apt/sources.list
---> Running in 8f9e01bfa26c
# deb http://snapshot.debian.org/archive/debian/20211220T000000Z bullseye main
deb http://mirrors.aliyun.com/debian bullseye main
# deb http://snapshot.debian.org/archive/debian-security/20211220T000000Z bullseye-security main
deb http://security.debian.org/debian-security bullseye-security main
# deb http://snapshot.debian.org/archive/debian/20211220T000000Z bullseye-updates main
deb http://mirrors.aliyun.com/debian bullseye-updates main
---> 31b85471cc1d
Removing intermediate container 8f9e01bfa26c
Step 4/8 : RUN apt-get clean
---> Running in ac9972b43e39
---> b60094be7966
Removing intermediate container ac9972b43e39
Step 5/8 : RUN apt-get update
---> Running in 887eff83d779
Get:1 http://mirrors.aliyun.com/debian bullseye InRelease [116 kB]
Get:2 http://mirrors.aliyun.com/debian bullseye-updates InRelease [44.1 kB]