下载包
[root@node0 ~]# wget http://nginx.org/download/nginx-1.14.2.tar.gz
创建安装目录
[root@node0 ~]# tree nginx-install/
nginx-install/
├── Dockerfile
└── nginx-1.14.2.tar.gz
编辑Dockerfile文件
[root@node0 ~]# vim nginx-install/Dockerfile
FROM centos:latest
LABEL MAINTAINER "FXX Fxx@123.com"
ADD ./nginx-1.14.2.tar.gz /usr/local/src
ENV PATH /usr/local/nginx/sbin:$PATH
RUN yum -y install bzip2 make openssl-devel pcre-devel expat-devel libtool gcc gcc-c++ libxml2-devel
RUN useradd -s /sbin/nologin nginx
WORKDIR /usr/local/src/nginx-1.14.2
RUN /bin/bash ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx
RUN make && make install
RUN ln -s /usr/local/nginx/sbin/nginx /usr/sbin/nginx
EXPOSE 80
CMD ["/usr/sbin/nginx", "-g" ,"daemon off;"]
创建nginx镜像
docker build -t nginx/web:v1.2 nginx-install/
运行容器
[root@node0 ~]# docker run -itd -p 80:80 --name web nginx/web:v1.2
进入查看端口
[root@node0 ~]# docker exec -it web /bin/bash
[root@6c7909e28e3b nginx-1.14.2]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 0.0.0.0:80 0.0.0.0:*