1.编写Dockerfile文件,添加如下内容并保存
命令:
vim Dockerfile
[root@centos79 ~]# cat Dockerfile
FROM centos:centos7
MAINTAINER ztj
ENV PATH /usr/local/nginx/sbin:$PATH
ADD nginx-1.8.0.tar.gz /usr/local/
ADD epel-release-latest-7.noarch.rpm /usr/local/
RUN rpm -ivh /usr/local/epel-release-latest-7.noarch.rpm
RUN yum install -y vim net-tools wget lftp gcc gcc-c++ make openssl-devel pcre-devel pcre && yum clean all
RUN useradd -s /sbin/nologin -M www
WORKDIR /usr/local/nginx-1.8.0
RUN ./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --with-pcre && make && make install
RUN echo "daemon off;" >>/etc/nginx.conf
EXPOSE 80
ENTRYPOINT ["nginx"]
CMD ["-g","daemon off;"]
[root@centos79 ~]#
2.构建镜像及查看
命令:
docker build -t centos-nginx:1.0 -f /root/Dockerfile .
[root@centos79