修改Dockerfile中apt與pip源為國內鏡像加速構建


更新:
構建鏡像時每個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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM