docker构建nginx

   

下载nginx1.14.0

mkdir nginx
cd nginx
wget http://nginx.org/download/nginx-1.14.0.tar.gz

Dockerfile

vi Dockerfile
FROM centos:7.2.1511
ENV TZ=Asia/Shanghai

RUN yum -y install epel* \
    yum -y install gcc openssl openssl-devel  pcre-devel zlib-devel

ADD nginx-1.14.0.tar.gz /opt/

WORKDIR /opt/nginx-1.14.0

RUN ./configure --prefix=/opt/nginx  --http-log-path=/opt/nginx/logs/access.log --error-log-path=/opt/nginx/logs/error.log --http-client-body-temp-path=/opt/nginx/client/  --http-proxy-temp-path=/opt/nginx/proxy/  --with-http_stub_status_module --with-file-aio --with-http_flv_module --with-http_gzip_static_module --with-stream --with-threads --user=www --group=www
RUN make && make install
RUN groupadd www && useradd -g www www
WORKDIR /opt/nginx
RUN rm -rf /opt/nginx-1.14.0

ENV NGINX_HOME=/opt/nginx
ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/nginx/sbin

EXPOSE 80 443
CMD /bin/sh -c 'nginx -g "daemon off;"'

构建

docker build -t shencifang/nginx:V1 .

创建容器启动nginx

docker images
REPOSITORY              TAG                 IMAGE ID            CREATED             SIZE
shencifang/nginx        V1                  867e93a6738c        38 seconds ago      427MB
docker run -itd 867e /bin/bash
docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
4b44fa918f6b        867e                "/bin/bash"         5 seconds ago       Up 5 seconds        80/tcp, 443/tcp     elastic_gates
docker exec -it 4b44 /bin/bash
nginx
ps -ef
UID         PID   PPID  C STIME TTY          TIME CMD
root          1      0  0 15:17 pts/0    00:00:00 /bin/bash
root         14      0  0 15:18 pts/1    00:00:00 /bin/bash
root         29      0  0 15:18 ?        00:00:00 nginx: master process nginx
www          30     29  0 15:18 ?        00:00:00 nginx: worker process
root         31     14  0 15:18 pts/1    00:00:00 ps -ef


发表评论