【问题标题】:Debian with nginx docker image won't update带有 nginx docker 映像的 Debian 不会更新
【发布时间】:2019-03-03 22:13:42
【问题描述】:

我在基于 Debian 的 docker 镜像中构建 nginx。每次我运行它时,它都会向我显示当前的 nginx 版本 nginx/1.10.3。我需要它来下载最新的稳定版 nginx。

这是我的Dockerfile

FROM debian:latest

RUN apt-get -y update

RUN apt-get install -yq gnupg2
RUN apt-get install -yq software-properties-common
RUN apt-get install -yq lsb-release
RUN apt-get install -yq curl

RUN add-apt-repository "deb http://archive.canonical.com/ $(lsb_release -sc) partner"
RUN add-apt-repository "deb http://nginx.org/packages/debian `lsb_release -cs` nginx"

RUN apt-get install -y nginx

RUN rm -rf /var/lib/apt/lists/

RUN echo "\ndaemon off;" >> /etc/nginx/nginx.conf

EXPOSE 80
CMD ["/usr/sbin/nginx"]

【问题讨论】:

    标签: docker nginx debian dockerfile


    【解决方案1】:

    Docker 镜像层用作后续构建的缓存。如果不对 Dockerfile 进行某种更改,您很可能会获得 nginx 1.10.3,因为它是从以前的构建中缓存的。

    你应该使用官方的nginx image,而不是构建你自己的nginx镜像,并选择你想要的版本的标签(例如,1.15.9)。

    【讨论】:

    • 如何添加一个新的存储库以便从中下载 nginx?我在 docker 映像中找到了最新版本,因此我可以向其中添加 vts 模块
    • 就像这个答案所说,不要;相反,请使用官方的nginx Docker 镜像并从那里获取。
    【解决方案2】:

    首先,很简单,您需要 apt-get update 从您添加的存储库中获取索引文件,然后 apt 将在那里找到任何包。

    RUN add-apt-repository blah blah
    RUN apt-get update -y   # Add this
    RUN apt-get install -y whatever
    

    而且,您在 add-apt-repository 部分中有无效的存储库。 lsb_release -sc 的输出是一个像 stretch 这样的 Debian 代号,当然,Canonical 合作伙伴 repo 没有相应的部分;和the NGninx repo only supports Debian squeeze(尽管我希望这些软件包也可以在较新版本的 Debian 上运行)。

    最后,您需要管理这些存储库的密钥,或者以其他方式将它们标记为安全。作为一个小小的奖励,我尝试稍微压缩您的apt-get 下载量。试试这个 Dockerfile:

    FROM debian:latest
    
    RUN apt-get -y update
    RUN apt-get install -yq gnupg2 \
        software-properties-common curl # lsb-release
    
    # XXX FIXME: the use of [trusted=yes] is really quick and dirty
    RUN add-apt-repository "deb [trusted=yes] http://archive.canonical.com/ bionic partner"
    RUN add-apt-repository "deb [trusted=yes] http://nginx.org/packages/debian squeeze nginx"
    
    RUN apt-get update -y    
    RUN apt-get install -y nginx
    
    RUN rm -rf /var/lib/apt/lists/
    
    RUN echo "\ndaemon off;" >> /etc/nginx/nginx.conf
    
    EXPOSE 80
    CMD ["/usr/sbin/nginx"]
    

    【讨论】:

    • 它告诉我一个错误(add-apt-repository 返回了一个非零代码)
    • 那是你原来的 Dockerfile 中的一个缺陷,而不是这个添加。
    • 顺便说一句,可能像上一行一样用现代命令替换替换反引号。
    • 在构建 Dockerfile 时,有没有其他方法可以让我获得最新的稳定 nginx?即使它在另一个发行版映像上……我所需要的只是一个 dockerfile,每次我运行它时都会安装 nginx 最新稳定版
    • 找到一个没有损坏的仓库...? nginx.com/resources/wiki/start/topics/tutorials/install 似乎只有一个已过时的 Debian Squeeze 存储库,但它可能也适用于较新的版本。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-27
    • 1970-01-01
    • 2019-07-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多