Dockerfile安装nginx

1.新建并进入docker_demo文件夹

2. wget http://nginx.org/download/nginx-1.17.2.tar.gz

新建文件Dockerfile内容:

# base image
FROM centos

# MAINTAINER
MAINTAINER 1406563994@qq.com.com

# put nginx-1.17.2.tar.gz into /usr/local/src and unpack nginx
ADD nginx-1.17.2.tar.gz /usr/local/src

# running required command
RUN yum install -y gcc gcc-c++ glibc make autoconf openssl openssl-devel
RUN yum install -y libxslt-devel -y gd gd-devel  pcre pcre-devel
RUN useradd -M -s /sbin/nologin nginx

VOLUME ["/data"]

# change dir to /usr/local/src/nginx-1.17.2
WORKDIR /usr/local/src/nginx-1.17.2

# execute command to compile nginx
RUN ./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-file-aio --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module --with-http_image_filter_module  --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_auth_request_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_stub_status_module && make && make install

ENV PATH /usr/local/nginx/sbin:$PATH

EXPOSE 80

ENTRYPOINT ["nginx"]

CMD ["-g"]



3.构建

docker build -t centos_nginx_v1:v1 .

4.启动

docker run -d -p 80:80 --name=centos_nginx_v1 centos_nginx_v1:v1 -g "daemon off;"

5.浏览器访问80端口