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

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

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。

  1. FROM php:8.1-fpm
  2. 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/

  1. nginx=stable # 使用nginx=development获取最新的开发版本
  2. add-apt-repository ppa:nginx/$nginx
  3. apt update
  4. 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.

  1. FROM php:8.1-fpm
  2. 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/

  1. nginx=stable # use nginx=development for latest development version
  2. add-apt-repository ppa:nginx/$nginx
  3. apt update
  4. 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

  1. FROM php:8.1-fpm
  2. RUN apt update && apt -y install curl gnupg2 ca-certificates lsb-release debian-archive-keyring
  3. RUN curl https://nginx.org/keys/nginx_signing.key | gpg --dearmor | tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null
  4. 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
  5. RUN apt update && apt -y install nginx && rm -rf /var/lib/apt/lists/*
  6. EXPOSE 80/tcp
  7. CMD ["/usr/sbin/nginx", "-g", "daemon off;"]

构建镜像

  1. $ docker build . -t nginx-mainline-php81

检查镜像

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

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

  1. $ docker run nginx-mainline-php81 cat /etc/issue
  2. Debian GNU/Linux 12 \n \l
  3. $ docker run nginx-mainline-php81 nginx -v
  4. nginx version: nginx/1.25.1
  5. $ docker run nginx-mainline-php81 php -v
  6. PHP 8.1.20 (cli) (built: Jun 14 2023 05:51:39) (NTS)
  7. Copyright (c) The PHP Group
  8. Zend Engine v4.1.20, Copyright (c) Zend Technologies

以守护进程方式运行容器

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

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

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

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

  1. $ 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

  1. FROM php:8.1-fpm
  2. RUN apt update && apt -y install curl gnupg2 ca-certificates lsb-release debian-archive-keyring
  3. RUN curl https://nginx.org/keys/nginx_signing.key | gpg --dearmor | tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null
  4. 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
  5. RUN apt update && apt -y install nginx && rm -rf /var/lib/apt/lists/*
  6. EXPOSE 80/tcp
  7. CMD ["/usr/sbin/nginx", "-g", "daemon off;"]

Build image

  1. $ docker build . -t nginx-mainline-php81

Check images

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

Check OS, nginx and php versions in docker

  1. $ docker run nginx-mainline-php81 cat /etc/issue
  2. Debian GNU/Linux 12 \n \l
  3. $ docker run nginx-mainline-php81 nginx -v
  4. nginx version: nginx/1.25.1
  5. $ docker run nginx-mainline-php81 php -v
  6. PHP 8.1.20 (cli) (built: Jun 14 2023 05:51:39) (NTS)
  7. Copyright (c) The PHP Group
  8. Zend Engine v4.1.20, Copyright (c) Zend Technologies

Run container as daemon

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

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

  1. $ netstat -tupln | grep 90
  2. tcp 0 0 0.0.0.0:90 0.0.0.0:* LISTEN 28520/docker-proxy
  3. 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:

  1. $ 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:

确定