目录
4.关于python3.6,python3.6-dev等安装
1.apt-get安装慢
RUN sed -i s@/archive.ubuntu.com/@/mirrors.aliyun.com/@g /etc/apt/sources.list && \
apt-get clean && \
apt-get -y update && apt-get -y install *** && \
... && \
rm -rf /var/lib/apt/lists/*
2.关于pip安装慢
RUN python -m pip --default-time=500 install -i https://pypi.tuna.tsinghua.edu.cn/simple --upgrade pip
3.关于体量大的python库
RUN wget https://pypi.tuna.tsinghua.edu.cn/packages/69/60/f685fb2cfb3088736bafbc9bdbb455327bdc8906b606da9c9a81bae1c81e/torch-1.1.0-cp36-cp36m-manylinux1_x86_64.whl && \
python -m pip install -i https://pypi.tuna.tsinghua.edu.cn/simple torch-1.1.0-cp36-cp36m-manylinux1_x86_64.whl
4.关于python3.6,python3.6-dev等安装
这个在终端中很容易安装,但是在dockerfile中常出错,总结要么半夜安装or自行下载python3.6的包安装后,再安装dev(后者太繁琐,且还是需要再访问一遍这个网,所以还是找个网络好的时间吧,可以节约大量的时间):
# RUN wget https://www.python.org/ftp/python/3.6.8/Python-3.6.8.tgz && \
# mkdir /usr/local/python3 && \
# tar -xzvf Python-3.6.8.tgz && rm -f Python-3.6.8.tgz && \
# cd Python-3.6.8 && \
# ./configure prefix=/usr/local/python3 --with-ssl --enable-optimizations && \
# make && make install && \
# ln -s /usr/local/python3/bin/python3.6 /usr/bin/python3.6 && \
# ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3 && \
# cd .. && \
# rm -rf Python-3.6.8
RUN sh -c '/bin/echo -e "\n" | add-apt-repository ppa:deadsnakes/ppa' && \
apt-get update && apt-get -y install python3.6 \
python3.6-dev \
python3-pip && \
rm -rf /var/lib/apt/lists/*
总结:不要想着自己去下载多个python3.6依赖deb, 这些依赖项之间相互依赖,尝试过网上提到的多种解法都没成功的去同时安装多相互依赖的deb。
比如下面这种多依赖关系,难以安装(反例):
apt-get update && \
apt-get -y install libopenblas-dev && \
wget http://ppa.launchpad.net/deadsnakes/ppa/ubuntu/pool/main/p/python3.6/libpython3.6-stdlib_3.6.12-1+xenial1_amd64.deb && \
wget http://ppa.launchpad.net/deadsnakes/ppa/ubuntu/pool/main/p/python3.6/libpython3.6_3.6.12-1+xenial1_amd64.deb && \
wget http://ppa.launchpad.net/deadsnakes/ppa/ubuntu/pool/main/p/python3.6/python3.6-minimal_3.6.12-1+xenial1_amd64.deb && \
wget http://ppa.launchpad.net/deadsnakes/ppa/ubuntu/pool/main/p/python3.6/libpython3.6-dev_3.6.12-1+xenial1_amd64.deb && \
wget http://ppa.launchpad.net/deadsnakes/ppa/ubuntu/pool/main/p/python3.6/python3.6_3.6.12-1+xenial1_amd64.deb && \
wget http://ppa.launchpad.net/deadsnakes/ppa/ubuntu/pool/main/p/python3.6/python3.6-dev_3.6.12-1+xenial1_amd64.deb && \
apt-get -f install && dpkg -i libpython3.6-stdlib_3.6.12-1+xenial1_amd64.deb libpython3.6_3.6.12-1+xenial1_amd64.deb python3.6-minimal_3.6.12-1+xenial1_amd64.deb libpython3.6-dev_3.6.12-1+xenial1_amd64.deb python3.6_3.6.12-1+xenial1_amd64.deb python3.6-dev_3.6.12-1+xenial1_amd64.deb
5.安装常出错,循环执行吧
while ! sudo docker build -t your_imagename:your_imagetag -f ./Dockerfile . ; do sleep 2 ; done ; echo succeed
这个是网络不好的情况,如果是因为自己的语句写错了, 那就及时改吧,然后无意义。
网络不好的情况比如说:
Err:23 https://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1604/x86_64 InRelease
Clearsigned file isn't valid, got 'NOSPLIT' (does the network require authentication?)
Err:26 https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64 Release.gpg
The following signatures were invalid: NODATA 1 NODATA 2
Err:29 https://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1604/x86_64 Packages
Hash Sum mismatch
6.安装deb
RUN wget http://ppa.launchpad.net/deadsnakes/ppa/ubuntu/pool/main/p/python3.6/python3.6-dev_3.6.12-1+xenial1_amd64.deb && \
dpkg -i python3.6-dev_3.6.12-1+xenial1_amd64.deb
7.git clone下载失败问题
如果使用git clone一直下载不成功的话,考虑使用wget吧。指定版本下载方法:
复制出现的链接,使用如下命令就可以下载了:
RUN wget https://codeload.github.com/opencv/opencv/zip/3.4
8.最后的工作空间含义
ENV CAFFE_ROOT=/opt/caffe
WORKDIR $CAFFE_ROOT
对应着新建docker image下的container,进入时的默认路径。
9.后续编译
后续编译尽量在该版本基础上去添加新的层,前面的层就不需要重新编了。
添加一个新的RUN层吧。
10.运行编译
运行编译的时候尽量在一个目录下文件大小非常小的目录下。