你的浏览器不支持canvas

做你害怕做的事情,然后你会发现,不过如此。

Dockerfile中更换apt镜像源

时间: 作者: 黄运鑫

本文章属原创文章,未经作者许可,禁止转载,复制,下载,以及用作商业用途。原作者保留所有解释权。


  • 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]

对于本文内容有问题或建议的小伙伴,欢迎在文章底部留言交流讨论。