Debian with nginx docker 图像不会更新

Debian with nginx docker image won't update

我正在基于 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 图像层作为后续构建的缓存。如果 Docker 文件中没有某种更改,您可能会获得 nginx 1.10.3,因为它是从以前的构建中缓存的。

与其构建自己的 nginx 映像,不如使用官方 nginx image,并为您想要的版本选择标签(例如 1.15.9)。

首先,简单地说,您需要 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"]