Docker ubuntu apt-get更换国内源解决Dockerfile构建速度过慢

1. 问题

dockerfile中 使用ubuntu 镜像 执行 RUN apt-get -q update

&& apt-get -q install -y 更新巨慢

2. 解决

使用国内的镜像源即可解决问题,注意如果使用的 包比较冷门 或者国内镜像网站没同步过来 可能就下载不到镜像

在dockerfile中 执行安装包命令 或者 RUN apt-get -q update 之前 增加如下内容

java 复制代码
RUN  sed -i s@/archive.ubuntu.com/@/mirrors.aliyun.com/@g /etc/apt/sources.list
RUN  apt-get clean

示例

java 复制代码
RUN  sed -i s@/archive.ubuntu.com/@/mirrors.aliyun.com/@g /etc/apt/sources.list
RUN  apt-get clean

######
# Install common dependencies from packages. Versions here are either
# sufficient or irrelevant.
#
# WARNING: DO NOT PUT JAVA APPS HERE! Otherwise they will install default
# Ubuntu Java.  See Java section below!
######
# hadolint ignore=DL3008
RUN apt-get -q update \
    && apt-get -q install -y --no-install-recommends \
        apt-utils \
        bats \
        build-essential
相关推荐
具身小佬7 小时前
2D激光雷达发送的是什么信息
ubuntu
具身小佬15 小时前
#!/usr/bin/env python3是干嘛的
ubuntu
杨浦老苏16 小时前
自托管网页EPUB阅读器Codexa
docker·群晖·电子书·calibre·opds
杨浦老苏16 小时前
开源文件协作平台OpenCloud
docker·文件管理·群晖·协作
谢尔登16 小时前
10_从 React Hooks 本质看 useState
前端·ubuntu·react.js
zhangrelay19 小时前
三分钟云课实践速通--单片机原理与应用--Arduino--SimulIDE--
linux·单片机·嵌入式硬件·学习·ubuntu
weixin_3776348419 小时前
【MinerU】 Docker Compose 使用
docker·容器·mineru
孪生质数-19 小时前
Linux高危漏洞通报Copy Fail - CVE-2026-31431
linux·运维·服务器·ubuntu·网络安全·debian·cve-2026-31431
庚昀◟19 小时前
腾讯云 CVM + Docker + Jenkins + GitLab CI/CD 全流程指南(python、flask实现简单计算器)
python·ci/cd·docker·flask·jenkins
nudt_qxx20 小时前
Ubuntu 24.04/26.04 与 Windows 10/11 双系统时间不同步终极解决方案
windows·stm32·ubuntu