[转帖]Nginx的Docker容器化配置

nginx,docker,容器,配置 · 浏览次数 : 0

小编点评

**Dockerfile** ```dockerfile FROM centos:centos7MAINTAINER RUN yum -y install epel-release RUN yum -y install wget gcc make pcre-devel \ zlib-devel openssl-devel libxml2-devel libxslt-devel luajit GeoIP-devel \ gd-devel libatomic_ops-devel luajit-devel perl-devel perl-ExtUtils-Embed RUN cd /tmp # Download and extract OpenResty RUN wget https://openresty.org/download/openresty-1.15.8.2.tar.gz RUN tar zxmf openresty-1.15.8.2.tar.gz # Configure OpenResty RUN ./configure \ --with-threads \ --with-file-aio \ --with-http_ssl_module \ --with-http_v2_module \ --with-http_realip_module \ --with-http_addition_module \ --with-http_xslt_module=dynamic \ --with-http_image_filter_module=dynamic \ --with-http_geoip_module=dynamic \ --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_slice_module \ --with-http_stub_status_module \ --with-stream=dynamic \ --with-stream_ssl_module \ --with-stream_realip_module \ --with-stream_geoip_module=dynamic \ --with-libatomic \ --with-pcre-jit \ --with-stream_ssl_preread_module # Build the Nginx Docker image RUN gmake # Set environment variables and start Nginx COPY nginx /usr/local/nginx/nginx RUN ln -s /usr/local/openresty/nginx /usr/local/nginxRUN \ ln -sf /dev/stdout /usr/local/nginx/logs/access.log \ ENTRYPOINT ["nginx", "-g", "daemon off;"] ``` **使用说明** 1. 创建一个名为 `nginx` 的目录。 2. 保存以上代码的 Dockerfile 到该目录下。 3. 使用以下命令构建 Nginx Docker镜像: ``` docker build -t nginx:v1.0 . ``` 4. 启动 Nginx 服务: ``` docker run -p 80:80 nginx:v1.0 ``` **注意** * `nginx:v1.0` 表示使用 Docker Hub 上的 Nginx 镜像。您可以根据您的需求更改版本。 * 确保您已经安装了 Docker 和 Docker Hub。

正文

https://www.cnblogs.com/lizexiong/p/15032552.html

 

这里只是做一个简单的演示,基础镜像选用 CentOS 7,Nginx 选用 Nginx 的扩展版本 OpenResty 1.15.8.2。

  Nginx 镜像 Dockerfile 脚本如下:

 
FROM centos:centos7
MAINTAINER Nginx Dockerfile Write by John.Wang
RUN yum -y install epel-release && yum -y install wget gcc make pcre-devel \
    zlib-devel openssl-devel libxml2-devel libxslt-devel luajit GeoIP-devel \
    gd-devel libatomic_ops-devel luajit-devel perl-devel perl-ExtUtils-Embed

RUN cd /tmp && wget https://openresty.org/download/openresty-1.15.8.2.tar.gz  && \
    tar zxmf openresty-1.15.8.2.tar.gz && \
    cd openresty-1.15.8.2 && \
    ./configure \
        --with-threads \
        --with-file-aio \
        --with-http_ssl_module \
        --with-http_v2_module \
        --with-http_realip_module \
        --with-http_addition_module \
        --with-http_xslt_module=dynamic \
        --with-http_image_filter_module=dynamic \
        --with-http_geoip_module=dynamic \
        --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_slice_module \
        --with-http_stub_status_module \
        --with-stream=dynamic \
        --with-stream_ssl_module \
        --with-stream_realip_module \
        --with-stream_geoip_module=dynamic \
        --with-libatomic \
        --with-pcre-jit \
        --with-stream_ssl_preread_module && \
    gmake && gmake install
ENV PATH $PATH:/usr/local/nginx/sbin
RUN ln -s /usr/local/openresty/nginx /usr/local/nginx
RUN ln -sf /dev/stdout /usr/local/nginx/logs/access.log &&\
    ln -sf /dev/stderr /usr/local/nginx/logs/error.log
EXPOSE 80
ENTRYPOINT ["nginx", "-g", "daemon off;"]
 

在 Dockerfile 文件的同一目录下,执行如下命令构建 Nginx 的 Dokcer 镜像。

docker build -t nginx:v1.0 .

与[转帖]Nginx的Docker容器化配置相似的内容: