Docker Hub镜像加速器
- 安装docker:
curl -sSL http://acs-public-mirror.oss-cn-hangzhou.aliyuncs.com/docker-engine/internet | sh -
- 参考这篇注册阿里开发者,拿到专属加速器地址,类似于:https://xxxx.mirror.aliyuncs.com
- 参考Docker加速器下面的说明配置并重启docker,我是ubuntu 16.04,如下:
sudo mkdir -p /etc/systemd/system/docker.service.d
sudo tee /etc/systemd/system/docker.service.d/mirror.conf <<-'EOF'
[Service]
ExecStart=/usr/bin/docker daemon -H fd:// --registry-mirror=https://xxxx.mirror.aliyuncs.com
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
写Dockerfile
# image for portfolio
FROM ubuntu:16.04
MAINTAINER wwy version: 0.1
ENV LD_LIBRARY_PATH=/usr/local/lib
COPY ./sources.list /etc/apt/
RUN depends='make r-base r-base-dev' &&\
apt-get update &&\
apt-get install -y $depends
#anaconda
COPY ./Anaconda2-4.2.0-Linux-x86_64.sh /tmp/
RUN bash /tmp/Anaconda2-4.2.0-Linux-x86_64.sh -b
ENV PATH /root/anaconda2/bin:$PATH
#ta-lib
COPY ./ta-lib-0.4.0-src.tar.gz /tmp/
RUN cd /tmp &&\
tar -xzf ta-lib-0.4.0-src.tar.gz &&\
cd /tmp/ta-lib &&\
./configure &&\
make &&\
make install
#pip
COPY ./pip.conf /root/.config/pip/
COPY ./SuiteSparse-4.5.3.tar.gz /tmp/
ENV CVXOPT_SUITESPARSE_SRC_DIR=/tmp/SuiteSparse
RUN cd /tmp &&\
tar xzf SuiteSparse-4.5.3.tar.gz &&\
pip install celery flasgger flask rpy2 arch pymongo grpc protobuf cvxopt ta-lib grpcio seaborn
#Qi4Trade
COPY Qi4Trade /tmp/Qi4Trade
RUN cd /tmp/Qi4Trade/trunk &&\
python setup.py install
#SITxuk
COPY SITxuk /tmp/SITxuk
RUN cd /tmp &&\
R CMD build SITxuk &&\
R CMD INSTALL SITxuk_0.1.0.tar.gz
#ndparser
COPY ndparser.so /root/anaconda2/lib/python2.7/site-packages/
COPY ndparser-1.0-py2.7.egg-info /root/anaconda2/lib/python2.7/site-packages/
#clear
RUN apt-get purge -y --auto-remove make &&\
apt-get clean &&\
rm -rf /tmp/* &&\
rm -rf /var/lib/apt/lists/*
#porfolio-web
COPY portfolio-web /root/portfolio-web
COPY libgomp.so.1.0.0 /root/anaconda2/lib/
ENV FLASK_SETTINGS=/root/portfolio-web/trunk/api/dev
ENV PYTHONPATH=/root/portfolio-web/trunk
WORKDIR /root/portfolio-web/trunk
EXPOSE 8686
CMD ["python","api/server.py"]
# Add Tini. Tini operates as a process subreaper for jupyter. This prevents kernel crashes.
ENV TINI_VERSION v0.6.0
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /usr/bin/tini
RUN chmod +x /usr/bin/tini
ENTRYPOINT ["/usr/bin/tini", "--"]
EXPOSE 8888
CMD ["jupyter","notebook","--port=8888","--no-browser","--ip=0.0.0.0"]
Dockerfile要注意的点
- 用&&\把所有命令串起来在一个Run里执行,避免产生太多层
- 可以把/etc/apt/sources.list拷过去,加速apt-get install; 把pip.conf拷到/root/.config/pip/pip.conf,指向douban的源,加速pip install
- 所有安装都是silent mode, 包括: apt-get -y、anaconda -b等
- 报pip not found: anaconda不会自动把bin加入PATH,需要手工加:
ENV PATH /root/anaconda2/bin:$PATH
- 每个阶段的命令写在一起,从COPY+ENV+RUN,这样万一下面的COPY改了,还能重用以前的cache
- COPY要这么写:
COPY ta-lib /tmp/ta-lib
,如果只是COPY ta-lib /tmp/
只会把ta-lib里面的内容拷过去 - 国内的镜像源有时apt-get install的时候会报"Hash Sum mismatch"的错误,不覆盖/etc/apt/sources.list,用官方的就好
- 很多server比如nginx、jupyter都默认监听localhost,要改成0.0.0.0,才能在容器外访问
build + export image
docker build -t test:v0.1 .
docker run -i -p 8686:8686 test:v0.1
docker save test:v0.1 | gzip > portfolio.tar.zip
//复制到其他机器上,导入
docker load -i portfolio.tar.zip
作者:AlexanderYao
出处:http://alexanderyao.cnblogs.com/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。