容器構建時須要下載多種軟件,每每這是很是耗時間的。hub.docker.com原本就慢,尤爲是遇到存放在gcr.io/aws等上面的模塊就掛了,pip安裝python模塊是也較慢,conda的下載更是如蝸牛。node
加快容器構建時的下載速度,有多種方法:python
一、放在「外面的服務器」構建,而後傳送到aliyun等鏡像,下載速度就會快不少不少。git
二、添加proxy和pip、conda的鏡像。以下是給jupyterhub環境下使用構建的一個singleuser鏡像。github
# Copyright (c) Jupyter Development Team. # Distributed under the terms of the Modified BSD License. FROM jupyter/all-spark-notebook:5811dcb711ba LABEL maintainer="Databook Project,https://github.com/databooks<openthings@163.com>" USER root # ==================================================================== # Add proxy, using --build-arg "HTTP_PROXY=http://192.168.199.99:9999" ENV HTTP_PROXY ${HTTP_PROXY} ENV HTTPS_PROXY ${HTTP_PROXY} ENV http_proxy ${HTTP_PROXY} ENV https_proxy ${HTTP_PROXY} #Add conda install mirror: RUN echo $http_proxy && \ conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/ && \ conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/ && \ conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/ && \ conda config --set show_channel_urls yes #Add pip install mirror: RUN echo "[global] \ index-url = http://pypi.tuna.tsinghua/simple \ trusted-host = \ pypi.tuna.tsinghua \ timeout = 120 \ " > /etc/pip.conf # ==================================================================== # ==================================================================== USER $NB_UID RUN pip install --upgrade pip RUN pip install bs4 && \ pip install lxml && \ pip install ipyleaflet && \ pip install py4j && \ pip install pyspark && \ pip install mlflow && \ pip install airflow && \ pip install tushare RUN conda update -n base conda RUN conda install -y -c conda-forge nodejs=8.10.0 && \ conda install -y -c conda-forge tensorflow=1.8.0 && \ jupyter labextension install jupyter-leaflet # ==================================================================== ENV HTTP_PROXY "" ENV HTTPS_PROXY "" ENV http_proxy "" ENV https_proxy "" # ====================================================================
注意:docker
更多的參考:Databook-數據之書 服務器