首页 > 解决方案 > 我在哪里可以找到 docker 的 nginx(稳定)?

问题描述

我正在尝试制作一个包含 Nginx stable 最新使用 vts 模块编译的 dockerfile .... 我遇到了一个大问题,当我放入将下载的 docker 文件时我找不到一些汽车链接安装最新的稳定 nginx 我只能指定一个像 1.14.2 这样的版本有没有办法我可以修改我的 dockerfile 让它总是下载最新的,而不仅仅是一个版本?

这是我的码头文件

FROM debian:stretch-slim




RUN apt-get update && \
    apt-get install -y git wget libreadline-dev libncurses5-dev libpcre3-    dev libssl-dev perl make build-essential zlib1g-dev && \
    cd /tmp/ && \
    wget http://nginx.org/download/nginx-1.14.2.tar.gz && \
    git clone git://github.com/vozlt/nginx-module-vts.git && \
    tar zxvf nginx-1.14.2.tar.gz && \
    rm -f nginx-1.14.2.tar.gz && \
    cd nginx-1.14.2 && \
    ./configure --prefix=/tmp/nginx-1.14.2 --sbin-path=/usr/sbin/nginx --    modules-path=/usr/lib/nginx/modules --conf-path=/etc/nginx/nginx.conf \
    --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid \
    --lock-path=/var/run/nginx.lock --http-client-body-temp-    path=/var/cache/nginx/client_temp --http-proxy-temp-    path=/var/cache/nginx/proxy_temp \
    --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-    temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-    path=/var/cache/nginx/scgi_temp \
    --user=nginx --group=nginx --with-compat --with-file-aio --with-    threads --with-http_addition_module --with-http_auth_request_module \
    --with-http_dav_module --with-http_flv_module --with-    http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module \
    --with-http_random_index_module --with-http_realip_module --with-    http_secure_link_module --with-http_slice_module --with-http_ssl_module \
    --with-http_stub_status_module --with-http_sub_module --with-    http_v2_module --with-mail --with-mail_ssl_module --with-stream \
    --with-stream_realip_module --with-stream_ssl_module --with-    stream_ssl_preread_module \
    --with-cc-opt='-g -O2 -fdebug-prefix-map=/data/builder/debuild/nginx-    1.14.2/debian/debuild-base/nginx-1.14.2=. -specs=/usr/share/dpkg/no-pie-    compile.specs -fstack-protector-strong -Wformat -Werror=format-security -    Wp,-D_FORTIFY_SOURCE=2 -fPIC' \
    --with-ld-opt='-specs=/usr/share/dpkg/no-pie-link.specs -Wl,-z,relro -    Wl,-z,now -Wl,--as-needed -pie' \
    --add-module=/tmp/nginx-module-vts && \
    make && make install && \
    cp -f objs/nginx /usr/sbin/nginx && \
    apt-get clean && rm -rf /var/lib/apt/lists/*

CMD ["nginx", "-g", "daemon off;"] 

标签: dockernginx

解决方案


如果您正在寻找一种简单的方法来在从源代码编译 nginx 期间继续使用稳定版本,因为它没有一个直接的 url afaik,那么您可以将构建参数传递给您的 Dockerfile,如下所示:

...
ARG NGINX_STABLE_VERSION
RUN   wget http://nginx.org/download/nginx-${NGINX_STABLE_VERSION}.tar.gz
...

并运行如下构建命令以根据传递的参数继续下载 nginx 版本:

docker build --build-arg NGINX_STABLE_VERSION=1.14.2 .

但是,如果您正在寻找如何在自定义模块中继续使用 nginx 的官方 docker 映像 -假设您使用的所有自定义模块都支持动态模块功能,例如 vts 模块- 那么您可以通过使用多阶段构建来实现使用 nginx动态模块 功能。

根据nginx-module-vts 更改日志,支持将模块编译为动态模块,因此您可以进行多阶段构建,使用您想要的模块编译 nginx,然后将生成的文件复制到具有相同版本的 nginx 映像中让它起作用。

Nginx 稳定的图像可以在这里找到标记为stableword。

您现在需要做的就是修改 Dockerfile 并使其使用动态模块的方式,然后添加另一个阶段以使用从第一阶段生成的新模块的稳定映像,您可以在构建期间添加一个参数,例如:

...
ARG NGINX_STABLE_VERSION
RUN   wget http://nginx.org/download/nginx-${NGINX_STABLE_VERSION}.tar.gz
...

并像这样运行构建:

docker build --build-arg NGINX_STABLE_VERSION=1.14.2 .


更新:

Nginx 没有提供一个链接,您可以每次都使用它来获取稳定版本,因此您可以像下面这样解析下载页面的 html,以不断获取稳定版本的最新下载链接:

我们依赖 HTML 页面,从长远来看,这并不是最强大的解决方案。

echo "http://nginx.org$(curl -s http://nginx.org/en/download.html | grep -oP 'Stable version.*?\K(/download/.*?tar.gz)')"

输出:

http://nginx.org/download/nginx-1.14.2.tar.gz

在您的 Dockerfile 中,它可以是这样的:

确保您已安装 curl

RUN curl "http://nginx.org$(curl -s http://nginx.org/en/download.html | grep -oP 'Stable version.*?\K(/download/.*?tar.gz)')" --output nginx.tar.gz

推荐阅读