2

Docker Debian 镜像源替换

因多数默认的 Docker 镜像为国外的,而采用的镜像源也是国外的,故访问很慢,所以我们需要替换为国内的(比如阿里云或163等)。

注意: 不同版本的 Debian 镜像源地址不一样

Debian 7.x (wheezy)

# 更新apt-get源
RUN echo \
    deb http://mirrors.aliyun.com/debian/ wheezy main non-free contrib\
    deb http://mirrors.aliyun.com/debian/ wheezy-proposed-updates main non-free contrib\
    deb-src http://mirrors.aliyun.com/debian/ wheezy main non-free contrib\
    > /etc/apt/sources.list

Debian 8.x (jessie)

# 更新apt-get源
RUN echo \
    deb http://mirrors.aliyun.com/debian/ jessie main non-free contrib\
    deb http://mirrors.aliyun.com/debian/ jessie-proposed-updates main non-free contrib\
    deb-src http://mirrors.aliyun.com/debian/ jessie main non-free contrib\
    > /etc/apt/sources.list

Debian 9.x (stretch)

# 更新apt-get源
RUN echo \
    deb http://mirrors.aliyun.com/debian/ stretch main non-free contrib\
    deb-src http://mirrors.aliyun.com/debian/ stretch main non-free contrib\
    deb http://mirrors.aliyun.com/debian-security stretch/updates main\
    deb-src http://mirrors.aliyun.com/debian-security stretch/updates main\
    deb http://mirrors.aliyun.com/debian/ stretch-updates main non-free contrib\
    deb-src http://mirrors.aliyun.com/debian/ stretch-updates main non-free contrib\
    deb http://mirrors.aliyun.com/debian/ stretch-backports main non-free contrib\
    deb-src http://mirrors.aliyun.com/debian/ stretch-backports main non-free contrib\
    > /etc/apt/sources.list

Laradock 镜像构建失败

因为默认用的是国外 Debian 镜像源,故在执行 apt-get 等命令拉取软件包时会失败,我们需手动在对于的 Dockerfile 中添加一个 RUN 指令来替换掉默认的镜像源

以下仅为示例:

需根据自己当前 Laradock 版本查看引用的系统镜像及其版本注意不同,其他系统(eg: CentOS)请对症下药。
# 更新apt-get源
RUN echo \
    deb http://mirrors.aliyun.com/debian/ stretch main non-free contrib\
    deb-src http://mirrors.aliyun.com/debian/ stretch main non-free contrib\
    deb http://mirrors.aliyun.com/debian-security stretch/updates main\
    deb-src http://mirrors.aliyun.com/debian-security stretch/updates main\
    deb http://mirrors.aliyun.com/debian/ stretch-updates main non-free contrib\
    deb-src http://mirrors.aliyun.com/debian/ stretch-updates main non-free contrib\
    deb http://mirrors.aliyun.com/debian/ stretch-backports main non-free contrib\
    deb-src http://mirrors.aliyun.com/debian/ stretch-backports main non-free contrib\
    > /etc/apt/sources.list

感谢您的阅读,觉得内容不错,点个赞吧 😆
原文地址: https://shockerli.net/post/replace-docker-laradock-debian-mirrors/


Jioby
2.9k 声望1.7k 粉丝

无善无恶心之体,有善有恶意之动。知善知恶是良知,为善去恶是格物。