我们通过基础的镜像构建自己的镜像及容器时,往往需要安装各种应用程序,这时候我们会碰到安装慢的问题。同在 Linux 上安装相关应用程序一样缓慢一样,在国内我们往往需要配置相关应用程序的镜像源来解决。下面我们来介绍几种常用镜像源配置。
pip
方法一:
在 Dockerfile 文件中添加
ARG PIP_INDEX_URL="https://pypi.tuna.tsinghua.edu.cn/simple"RUN pip config set global.index-url ${PIP_INDEX_URL}
方法二:
使用 COPY 命令复制配置好的 pip.conf 文件到容器中的指定路径:
COPY pip.conf ~/.pip/
# COPY pip.conf /etc/.pip/
# COPY pip.conf ~/.config/pip/
debian
ARG MIRROR="mirrors.aliyun.com"
RUN sed -i "s@http://deb.debian.org@https://${MIRROR}@g" /etc/apt/sources.list
&& apt-get update && apt-get upgrade
ubuntu
ARG MIRROR="mirrors.aliyun.com"
RUN sed -i s/archive.ubuntu.com/${MIRROR}/g /etc/apt/sources.list \
&& apt-get update && apt-get upgrade
alpine
ARG MIRROR="mirrors.tuna.tsinghua.edu.cn"
RUN sed -i 's/dl-cdn.alpinelinux.org/${MIRROR}/g' /etc/apk/repositories \
&& apk update && apk upgrade \
&& apk add --no-cache bash \
&& rm -rf /var/cache/apk/* \
