更新:
构建镜像时每个RUN命令都会产生一个layer
为了控制镜像层数与体积,尽量把需要的命令写在一行,如
RUN mkdir build; cd build
原文:
从Github下载一些工程通常配有指定环境的Dockerfile需要自己build
其中涉及apt与pip的安装指令因为网络关系下载缓慢 耗费时间
通过添加RUN语句替换国内镜像加速
FROM ubuntu:16.04
# Using aliyun ubuntu mirror
RUN sed -i s@/archive.ubuntu.com/@/mirrors.aliyun.com/@g /etc/apt/sources.list
RUN apt update
# Install all system pre-reqs
RUN apt install apt-utils \
build-essential \
curl \
git \
cmake \
unzip \
autoconf \
autogen \
libtool \
mlocate \
zlib1g-dev \
python \
python3-dev \
python3-pip \
-y
# Using douban pipy mirror
RUN pip3 install -i https://pypi.douban.com/simple/ -U pip
RUN pip3 config set global.index-url https://pypi.douban.com/simple/
# Install packages you need
RUN pip3 install scipy==0.19.1 \
numpy==1.14.0 \
torch==0.4.1 \
opencv_python==3.4.0.12 \
vispy==0.5.3 \
tensorflow==1.11.0 \
PyYAML==3.13 \
enum34==1.1.6 \
matplotlib==3.0.3
另外,执行docker build .
默认会把当前整个目录传入构建镜像
为节省时间,尽量选干净的文件夹放置Dockerfile