参考链接:https://blog.fundebug.com/2017/05/15/write-excellent-dockerfile/
为什么不能使用 commit 制作的镜像
https://yeasy.gitbooks.io/docker_practice/content/image/commit.html
要把经常改动的部分放在 dockerfile 的后面
docker 镜像的缓存是一层一层的堆上去的,如果把经常更改的代码放在前面,那么后面的缓存层全部失效了。如下面代码所示,如果把 sqlaudit 的项目代码放到第6层,那么后面的 Python 也要重新编译安装,修改下代码就让让人痛不欲生。
FROM centos:7
MAINTAINER kougazhang
WORKDIR /kylin
ENV PATH="/kylin:usr/bin:${PATH}"
COPY ./sqlaudit_package /kylin/sqlaudit_package/
RUN yum groupinstall -y "Development Tools" && \
yum -y update zlib* && \
yum -y install zlib* && \
yum install -y openssl-devel && \
yum localinstall -y /kylin/sqlaudit_package/oracle-instantclient12.1-basic-12.1.0.2.0-1.x86_64.rpm && \
sh -c "echo /usr/lib/oracle/12.1/client64/lib > /etc/ld.so.conf.d/oracle-instantclient.conf" && \
ldconfig && \
echo 'export LD_LIBRARY_PATH=/usr/lib/oracle/12.1/client64/lib:$LD_LIBRARY_PATH' >> ~/.bash_profile && \
mkdir -p /usr/lib/oracle/12.1/client64/lib/network/admin && \
/kylin/sqlaudit_package/Python-3.6.0/configure --prefix=/usr/local/python3 --with-ssl && \
make && \
make install && \
ln -s /usr/local/python3/bin/python3 /usr/bin/python3 && \
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3 && \
rm -r /usr/local/python3/lib/python3.6/site-packages && \
mv /kylin/sqlaudit_package/site-packages/ /usr/local/python3/lib/python3.6/
COPY ./sqlaudit /kylin/sqlaudit/
RUN /usr/bin/pip3 install --no-cache -r /kylin/sqlaudit/rq3.txt
EXPOSE 8000
EXPOSE 22
CMD python3 sqlaudit/main.py