容器构建时须要下载多种软件,每每这是很是耗时间的。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-数据之书 服务器