基于docker升级openresty1.21.4.1

文章讲述了如何在Docker容器中基于现有的openresty1.19.3.1镜像升级到1.21.4.1版本,包括拉取镜像、备份、编译过程中遇到的问题及解决方案,最终打包新镜像的过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

目录

 1、把基础镜像拉到本地

 2、备份原镜像

 3、运行镜像,不要退出容器

4、打开一新的终端,把openresty拷到镜像里面

 5、在容器中编译安装openresty

5.1 容器中cofigure时报错

 5.2尝试解决

 5.3容器中安装gcc报错

 5.4解决gcc无法安装的错误

 5.5容器中重新编译

6.删除容器中的openresty-1.21.4.1.tar.gz、openresty-1.21.4.1

7.打开一个新的终端,通过容器打包镜像


情况说明:

原来的openresty1.19.3.1应该也是在运行的容器中编译openresty打包成的镜像。

基于该基础上升级openresty到1.21.4.1,来解决漏洞

 1、把基础镜像拉到本地

[root@master ~]# docker pull 192.168.58.130:5000/test/openresty:base

 2、备份原镜像

[root@master ~]# docker tag 192.168.58.130:5000/test/openresty:base  192.168.58.130:5000/test/openresty:base20230808

 3、运行镜像,不要退出容器

 [root@master ~]# docker run -ti --name base 192.168.58.130:5000/test/openresty:base

root@4decf62a3d87:/# 

4、打开一新的终端,把openresty拷到镜像里面

[root@master ~]# wget https://openresty.org/download/openresty-1.21.4.1.tar.gz

[root@master ~]# docker cp openresty-1.21.4.1.tar.gz base:/usr/src

 5、在容器中编译安装openresty

root@4decf62a3d87:/#  cd /usr/src
#解压tar包
root@4decf62a3d87:/usr/src# tar xvf openresty-1.21.4.1.tar.gz
root@4decf62a3d87:/usr/src# cd openresty-1.21.4.1
#编译configure,编译的参数根据情况自由选择
root@4decf62a3d87:/usr/src/openresty-1.21.4.1# ./configure --prefix=/usr/local/openresty \
--with-threads \
--with-file-aio \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_xslt_module=dynamic \
--with-http_image_filter_module=dynamic \
--with-http_geoip_module=dynamic \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_auth_request_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_degradation_module \
--with-http_slice_module \
--with-http_stub_status_module \
--with-stream_ssl_module \
--with-stream_realip_module \
--with-stream_geoip_module=dynamic \
--with-stream_ssl_preread_module \
--with-compat \
--with-pcre-jit

5.1 容器中cofigure时报错

make[1]: cc: Command not found

#没有gcc导致的

 5.2尝试解决

root@4decf62a3d87::/usr/src/openresty-1.21.4.1# apt-get install -y gcc

 5.3容器中安装gcc报错

 

 5.4解决gcc无法安装的错误

[root@master ~]# wget http://mirrors.163.com/.help/sources.list.buster

[root@master ~]# docker cp sources.list.buster base:/etc/apt

#容器中重新下载gcc等依赖包

root@4decf62a3d87:/# cd /etc/apt
root@4decf62a3d87:/etc/apt# mv sources.list sources.list.bak
root@4decf62a3d87:/etc/apt# mv sources.list.buster sources.list
root@4decf62a3d87:/etc/apt# apt-get update
root@4decf62a3d87:/etc/apt# apt-get install -y gcc make libpcre3-dev openssl libssl-dev libxml2-dev libgd-dev libxml2 libgeoip-dev libxslt-dev zlib

####安装依赖成功####

 5.5容器中重新编译

#编译configure
root@4decf62a3d87:/usr/src/openresty-1.21.4.1:# ./configure --prefix=/usr/local/openresty \
--with-threads \
--with-file-aio \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_xslt_module=dynamic \
--with-http_image_filter_module=dynamic \
--with-http_geoip_module=dynamic \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_auth_request_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_degradation_module \
--with-http_slice_module \
--with-http_stub_status_module \
--with-stream_ssl_module \
--with-stream_realip_module \
--with-stream_geoip_module=dynamic \
--with-stream_ssl_preread_module \
--with-compat \
--with-pcre-jit

root@4decf62a3d87:/usr/src/openresty-1.21.4.1# make
root@4decf62a3d87:/usr/src/openresty-1.21.4.1# make install

#########至此openresty-1.21.4.1编译完成#########

6.删除容器中的openresty-1.21.4.1.tar.gz、openresty-1.21.4.1

root@4decf62a3d87:/usr/src# cd /usr/src
root@4decf62a3d87:/usr/src# rm -rf openresty-1.21.4.1.tar.gz openresty-1.21.4.1

7.打开一个新的终端,通过容器打包镜像

#打包镜像
 [root@master ~]# docker commit -m 'openresty-1.21.4.1' 4decf62a3d87 openresty:base-1.21.4.1

 之后,可以把新的镜像打包成tar包上传到所需的服务器上并导入后,推送到镜像仓库,参考如下:

#192.168.58.8机器上操作

1.打包本地虚拟机的镜像
docker save -o openresty.tar 192.168.58.8:5000/test/openresty:base1.21.4.1

#192.168.128.8机器上操作

2.把镜像tar包上传到虚拟机上,并导入
docker load < /root/openresty.tar 

3.给镜像打标签
docker tag f0796f9532be 192.168.128.8:5000/test/openresty:base1.21

4.推送镜像到仓库
docker push 192.168.128.8:5000/test/openresty:base1.21

### 官方 OpenResty Docker 镜像下载与使用 #### 获取官方镜像 为了获取并运行官方的 OpenResty Docker 镜像,可以利用 `docker pull` 命令来拉取最新的稳定版本。这一步骤能够确保所使用的软件包是最新的,并且经过了官方验证。 ```bash docker pull openresty/openresty:latest ``` 此命令会从 Docker Hub 上下载由 OpenResty 维护者发布的最新版镜像文件[^2]。 #### 启动容器实例 一旦镜像被成功下载到本地机器上,就可以通过下面这条指令快速启动一个新的容器: ```bash docker run -d -p 8080:80 openresty/openresty:latest ``` 上述命令中的 `-d` 参数表示以后台模式运行容器;而 `-p 8080:80` 则用于映射主机端口至容器内部的服务端口,在这里意味着访问本机 IP 地址加上指定端口号 (例如 http://localhost:8080/) 即可浏览正在运行于该容器内的 Web 应用程序服务。 对于更复杂的配置需求,比如自定义 Nginx 设置或集成其他依赖项,则可能需要创建基于官方镜像定制化的 Dockerfile 文件来进行构建工作。一个典型的例子如下所示: ```Dockerfile FROM openresty/openresty:alpine # 设置环境变量, 添加必要的路径 ENV PATH=/usr/local/openresty/nginx/sbin:$PATH \ NGINX_CONF_PATH=/etc/nginx/nginx.conf # 将外部配置复制进来 ADD nginx.conf ${NGINX_CONF_PATH} WORKDIR /app/ EXPOSE 80 CMD ["nginx", "-g", "daemon off;", "-c", "${NGINX_CONF_PATH}"] ``` 这段脚本首先指定了基础镜像为轻量级 Alpine Linux 版本上的 OpenResty 发行版,接着设置了几个有用的环境变量以便后续操作更加便捷。随后把宿主机上的 Nginx 主配置文件拷贝到了目标位置,并设置默认的工作目录以及暴露 HTTP 请求监听端口。最后给出了一条启动命令序列,它告诉容器如何正确地加载配置并保持前台进程活跃状态直到收到终止信号为止[^3]。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值