在Dockerfile中将nginx更新至最新版本1.24.0

huangapple go评论89阅读模式
英文:

Update nginx to latest version 1.24.0 in dockerfile

问题

我有一个Dockerfile,它使用php:8.1-fpm作为基础镜像,该镜像使用Debian 12。此镜像帮助我安装了Nginx版本1.22.1。由于安全漏洞,我需要升级Nginx到1.24.0。

FROM php:8.1-fpm

RUN apt-get update && apt-get install -y nginx=1.24.*

但这给我带来了错误,因为找不到1.24.*版本。

然后我尝试添加PPA存储库,并使用此链接中的信息升级Nginx:
https://www.nginx.com/resources/wiki/start/topics/tutorials/install/

nginx=stable # 使用nginx=development获取最新的开发版本
add-apt-repository ppa:nginx/$nginx
apt update
apt install nginx

但仍然没有成功。我仍然得到Nginx 1.22.1。

是否有任何方法可以在我的Docker镜像中升级Nginx?

提前感谢。

英文:

I have a dockerfile that uses php:8.1-fpm as the base image which uses debian 12. This image is helping me install nginx version 1.22.1. Not due to security vulnerabilities, I need to upgrade nginx to 1.24.0.

FROM php:8.1-fpm

RUN apt-get update && apt-get install -y nginx=1.24.* \

But this is giving me error as 1.24.* version not found.

Then I tried adding ppa repository and upgrading the nginx using information from this link:
https://www.nginx.com/resources/wiki/start/topics/tutorials/install/

nginx=stable # use nginx=development for latest development version
add-apt-repository ppa:nginx/$nginx
apt update
apt install nginx

But still no success. I am still getting nginx 1.22.1

Is there any way by which I can upgrade nginx in my docker image.

Thanks in advance.

答案1

得分: 0

Now mainline nginx version is 1.25.1, stable verion is 1.24.0

创建主线 nginx 版本的 Dockerfile

FROM php:8.1-fpm

RUN apt update && apt -y install curl gnupg2 ca-certificates lsb-release debian-archive-keyring
RUN curl https://nginx.org/keys/nginx_signing.key | gpg --dearmor | tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null
RUN echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] http://nginx.org/packages/mainline/debian `lsb_release -cs` nginx" | tee /etc/apt/sources.list.d/nginx.list
RUN apt update && apt -y install nginx && rm -rf /var/lib/apt/lists/*

EXPOSE 80/tcp
CMD ["/usr/sbin/nginx", "-g", "daemon off;"]

构建镜像

$ docker build . -t nginx-mainline-php81

检查镜像

$ docker images
REPOSITORY              TAG       IMAGE ID       CREATED         SIZE
nginx-mainline-php81    latest    8768a3a02d01   9 minutes ago   525MB

在 Docker 中检查操作系统、nginx 和 PHP 版本

$ docker run nginx-mainline-php81 cat /etc/issue
Debian GNU/Linux 12 \n \l

$ docker run nginx-mainline-php81 nginx -v
nginx version: nginx/1.25.1

$ docker run nginx-mainline-php81 php -v
PHP 8.1.20 (cli) (built: Jun 14 2023 05:51:39) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.20, Copyright (c) Zend Technologies

以守护进程方式运行容器

$ docker run -d --rm -p 90:80 nginx-mainline-php81
54a76f657d71024d95e3c4fae5f18b18b0040bbbab5ab17ecb0076468fd59f09

我们将主机的端口 90 映射到 Docker 容器的端口 80。检查 netstat

$ netstat -tupln | grep 90
tcp    0   0 0.0.0.0:90   0.0.0.0:*  LISTEN  28520/docker-proxy
tcp6   0   0 :::90        :::*       LISTEN  28527/docker-proxy

在浏览器中访问地址 SERVER_IP:90,您将看到 nginx 的默认页面。或者使用命令行的 curl 进行检查,例如:

$ curl 127.0.0.1:90

您将看到 nginx 默认页面的 HTML 源代码

英文:

Now mainline nginx version is 1.25.1, stable verion is 1.24.0

Create Dockerfile for mainline nginx version

FROM php:8.1-fpm

RUN apt update && apt -y install curl gnupg2 ca-certificates lsb-release debian-archive-keyring
RUN curl https://nginx.org/keys/nginx_signing.key | gpg --dearmor | tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null
RUN echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] http://nginx.org/packages/mainline/debian `lsb_release -cs` nginx" | tee /etc/apt/sources.list.d/nginx.list
RUN apt update && apt -y install nginx && rm -rf /var/lib/apt/lists/*

EXPOSE 80/tcp
CMD ["/usr/sbin/nginx", "-g", "daemon off;"]

Build image

$ docker build . -t nginx-mainline-php81

Check images

$ docker images
REPOSITORY              TAG       IMAGE ID       CREATED         SIZE
nginx-mainline-php81    latest    8768a3a02d01   9 minutes ago   525MB

Check OS, nginx and php versions in docker

$ docker run nginx-mainline-php81 cat /etc/issue
Debian GNU/Linux 12 \n \l

$ docker run nginx-mainline-php81 nginx -v
nginx version: nginx/1.25.1

$ docker run nginx-mainline-php81 php -v
PHP 8.1.20 (cli) (built: Jun 14 2023 05:51:39) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.20, Copyright (c) Zend Technologies

Run container as daemon

$ docker run -d --rm -p 90:80 nginx-mainline-php81
54a76f657d71024d95e3c4fae5f18b18b0040bbbab5ab17ecb0076468fd59f09

We mapping port 90 of host to the port 80 docker container. Check netstat:

$ netstat -tupln | grep 90
tcp    0   0 0.0.0.0:90   0.0.0.0:*  LISTEN  28520/docker-proxy
tcp6   0   0 :::90        :::*       LISTEN  28527/docker-proxy

Go to the browser and open address SERVER_IP:90, you can see nginx defaul page. Or check with curl from command line, like:

$ curl 127.0.0.1:90

You will see html source code of the nginx defaul page.

huangapple
  • 本文由 发表于 2023年6月30日 04:00:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/76584273.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定