镜像分层的好处:复用节省磁盘空间,相同的内容只需加载一份到内存
修改dockerfile之后,再次构建速度加快

docker优化:

1.尽可能地选择体积小的linux发行版,比如alpine
2.尽可能合并RUN指令,清理无用文件(yum缓存,源码包)
3.修改dockerfile,把变化的内容尽可能放在dockerfile结尾。
4.使用dockerignore,减少不必要的文件ADD /html

示例:可道云

[root@docker01 kod]# cat dockerfile 
###############
FROM centos:6.9
RUN curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo && \
curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo && \
yum install nginx php-fpm php-gd php-mbstring unzip -y && \
yum clean all


ADD www.conf /etc/php-fpm.d/www.conf 
ADD default.conf /etc/nginx/conf.d/default.conf


RUN mkdir /html
WORKDIR /html
RUN curl -o  kod.zip http://192.168.37.200/191127/kodexplorer4.40.zip && \
	unzip kod.zip && \ 
	rm -rf kod.zip && \
	chown -R nginx:nginx .

ADD init.sh /init.sh
EXPOSE 80
VOLUME /html
CMD ["/bin/bash","/init.sh"]
##############
构建为镜像
docker build -t kod:v3 --network=host .

查看镜像大小
docker image kod 

posted on 2019-12-05 16:23  杨港澳  阅读(90)  评论(0)    收藏  举报