使用基于 Ubuntu 的 Docker 时,如果需要 apt-get,默认的 ubuntu 源可能会非常慢,因此推荐更换为国内源,如阿里云等.
在 Dockerfile 文件更换阿里云源:
如:
FROM ubuntu:16.04
# Ali apt-get source.list
RUN mv /etc/apt/sources.list /etc/apt/sources.list.bak && \
echo "deb-src http://archive.ubuntu.com/ubuntu xenial main restricted" >/etc/apt/sources.list && \
echo "deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted" >>/etc/apt/sources.list && \
echo "deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted multiverse universe" >>/etc/apt/sources.list && \
echo "deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted" >>/etc/apt/sources.list && \
echo "deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted multiverse universe" >>/etc/apt/sources.list && \
echo "deb http://mirrors.aliyun.com/ubuntu/ xenial universe" >>/etc/apt/sources.list && \
echo "deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe" >>/etc/apt/sources.list && \
echo "deb http://mirrors.aliyun.com/ubuntu/ xenial multiverse" >>/etc/apt/sources.list && \
echo "deb http://mirrors.aliyun.com/ubuntu/ xenial-updates multiverse" >>/etc/apt/sources.list && \
echo "deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse" >>/etc/apt/sources.list && \
echo "deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse" >>/etc/apt/sources.list && \
echo "deb http://archive.canonical.com/ubuntu xenial partner" >>/etc/apt/sources.list && \
echo "deb-src http://archive.canonical.com/ubuntu xenial partner" >>/etc/apt/sources.list && \
echo "deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted" >>/etc/apt/sources.list && \
echo "deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted multiverse universe" >>/etc/apt/sources.list && \
echo "deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe" >>/etc/apt/sources.list && \
echo "deb http://mirrors.aliyun.com/ubuntu/ xenial-security multiverse" >>/etc/apt/sources.list
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
ca-certificates \
vim \
python \
libopencv-dev \
python-pip \
&& rm -rf /var/lib/apt/lists/*
RUN pip install --upgrade pip \
numpy \
pymongo \
opencv-python
Ubuntu20.04:
FROM ubuntu:20.04
RUN mv /etc/apt/sources.list /etc/apt/sources.list.bak && \
echo "deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted" >/etc/apt/sources.list && \
echo "deb http://mirrors.aliyun.com/ubuntu/ focal universe" >/etc/apt/sources.list && \
echo "deb http://mirrors.aliyun.com/ubuntu/ focal-updates universe" >/etc/apt/sources.list && \
echo "deb http://mirrors.aliyun.com/ubuntu/ focal multiverse" >/etc/apt/sources.list && \
echo "deb http://mirrors.aliyun.com/ubuntu/ focal-updates multiverse" >/etc/apt/sources.list && \
echo "deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse" >/etc/apt/sources.list && \
echo "deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted" >/etc/apt/sources.list && \
echo "deb http://mirrors.aliyun.com/ubuntu/ focal-security universe" >/etc/apt/sources.list && \
echo "deb http://mirrors.aliyun.com/ubuntu/ focal-security multiverse" >/etc/apt/sources.list
One comment
thx