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
相关推荐
yashuk7 小时前
Ubuntu 系统下安装 Nginx
数据库·nginx·ubuntu
说实话起个名字真难啊8 小时前
docker入门之单进程哲学与多进程管理
docker
拾贰_C9 小时前
【Ubuntu | Nvidia 】nvidia 驱动安装
linux·运维·ubuntu
Kapibalapikapi9 小时前
Web笔记 | docker常用指令 --搭建测试靶场
web安全·docker·容器
ノBye~10 小时前
Docker Compose
运维·docker·容器
释怀不想释怀10 小时前
安装Docker(Centos)
docker·eureka·centos
Mr成文10 小时前
【Linux/Ubuntu】OpenCode +Oh My OpenAgent安装配置实践
linux·运维·ubuntu
YoungHong199210 小时前
Claude Code & 智谱GLM-5.1 环境配置指南 (Windows/macOS/Ubuntu)
windows·ubuntu·macos
超b小哥10 小时前
【超详细】Claude Code Ubuntu平台完整部署指南
linux·人工智能·ubuntu·ai·claude code
搬砖魁首10 小时前
Fabric系列 - HSM之2 容器化
docker·fabric·hsm·bccsp·pkcs11