dockerfile未优化版nginx
FROM centos:7 ##基于centos:7镜像
RUN yum install -y gcc pcre pcre-devel devel zlib-devel make ##安装依赖环境
ADD nginx-1.12.2.tar.gz /mnt ##将源码复制到指定目录,并解压
WORKDIR /mnt/nginx-1.12.2 ##为下面的指令指定执行目录
RUN sed -i 's/CFLAGS="$CFLAGS -g"/#CFLAGS="$CFLAGS -g"/g' auto/cc/gcc ##关闭Debug调试
RUN ./configure --prefix=/usr/local/nginx ##安装编译
RUN make
RUN make install
EXPOSE 80
VOLUME ["/usr/local/nginx/html"] ##指定挂载点
CMD ["/usr/local/nginx/sbin/nginx","-g","daemon off;"] ##为了保持nginx的容器不>退出,关闭nginx后台运行
[root@localhost nginx]# docker build -t nginx:1 . ##使用当前目录下的文件构建标签为nginx:1的镜像
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/785ba9771b461b75786be17d2c4cd99c.png)
优化1.不需要输出的指令丢入/dev/null
FROM centos:7
RUN yum install -y gcc pcre pcre-devel devel zlib-devel make &> /dev/null $$yum clean all
ADD nginx-1.12.2.tar.gz /mnt
WORKDIR /mnt/nginx-1.12.2
RUN sed -i 's/CFLAGS="$CFLAGS -g"/#CFLAGS="$CFLAGS -g"/g' auto/cc/gcc
RUN ./configure --prefix=/usr/local/nginx
RUN make &> /dev/null
RUN make install