当前位置: 首页 > news >正文

编译docker版openresty

使用alpine为基础镜像

# 使用Alpine作为基础镜像
FROM alpine:3.18# 替换为阿里云镜像源,并安装必要的依赖
RUN sed -i 's|https://dl-cdn.alpinelinux.org/alpine|https://mirrors.aliyun.com/alpine|g' /etc/apk/repositories && \apk add --no-cache \build-base \pcre-dev \openssl-dev \zlib-dev \perl \linux-headers \&& mkdir -p /usr/local/openresty# 下载OpenResty源码包
WORKDIR /tmp
RUN wget https://openresty.org/download/openresty-1.21.4.1.tar.gz && \tar zxpf openresty-1.21.4.1.tar.gz# 编译并安装OpenResty
WORKDIR /tmp/openresty-1.21.4.1
RUN ./configure --prefix=/usr/local/openresty \--with-pcre-jit \--with-http_ssl_module \--with-http_v2_module \--with-http_realip_module \--with-http_stub_status_module \-j2 && \make && \make install# 清理无用文件
RUN rm -rf /tmp/openresty-1.21.4.1*# 设置工作目录
WORKDIR /usr/local/openresty# 暴露端口
EXPOSE 80# 启动命令
CMD ["/usr/local/openresty/nginx/sbin/nginx", "-g", "daemon off;"]

上面编译完457M,多阶段构建可以缩减至25.7M

# stage 1: 构建阶段
FROM alpine:3.18 AS builder# 替换为阿里云源并安装构建依赖
RUN sed -i 's|https://dl-cdn.alpinelinux.org/alpine|https://mirrors.aliyun.com/alpine|g' /etc/apk/repositories && \apk add --no-cache \build-base \pcre-dev \openssl-dev \zlib-dev \perl \linux-headers# 下载并解压 OpenResty 源码
WORKDIR /tmp
RUN wget https://openresty.org/download/openresty-1.21.4.1.tar.gz && \tar zxpf openresty-1.21.4.1.tar.gz# 编译安装 OpenResty
WORKDIR /tmp/openresty-1.21.4.1
RUN ./configure --prefix=/usr/local/openresty \--with-pcre-jit \--with-http_ssl_module \--with-http_v2_module \--with-http_realip_module \--with-http_stub_status_module \-j2 && \make && \make install# 剥离可执行文件
RUN strip /usr/local/openresty/nginx/sbin/nginx# stage 2: 最终运行环境
FROM alpine:3.18# 安装运行时依赖
RUN sed -i 's|https://dl-cdn.alpinelinux.org/alpine|https://mirrors.aliyun.com/alpine|g' /etc/apk/repositories && \apk add --no-cache \libgcc \pcre \openssl \zlib# 复制编译好的 OpenResty 文件
COPY --from=builder /usr/local/openresty /usr/local/openresty# 设置工作目录
WORKDIR /usr/local/openresty# 暴露端口
EXPOSE 80# 启动命令
CMD ["/usr/local/openresty/nginx/sbin/nginx", "-g", "daemon off;"]

编译arm版docker

需要安装dockerbuildx

docker buildx create --use --name=mybuilder-cn --driver docker-container --driver-opt image=uhub.service.ucloud.cn/iatc/cn-buildkit:latest
docker buildx use mybuilder-cn
docker buildx build --platform linux/arm/v7 -t openresty-arm:latest . --load
docker buildx rm mybuilder-cn

相关文章:

  • huggingface transformers中Dataset是一种什么数据类型
  • # 07_Elastic Stack 从入门到实践(七)---2
  • Memcached 服务搭建和集成使用的详细步骤示例
  • STM32-DMA数据转运(8)
  • MyBatis与MyBatis-Plus深度分析
  • 测试报告--博客系统
  • vue3父子组件传值
  • Linux系统编程---Signal信号集
  • Datawhale PyPOTS时间序列5月第1次笔记
  • 【速写】TRL:Trainer的细节与思考(PPO/DPO+LoRA可行性)
  • JavaWeb 开发的核心基础知识
  • 2025-05-13 学习记录--Python-条件判断:if语句 + if-else语句 + if-elif-else语句 + match语句
  • 码蹄集——分解、数组最大公约数、孪生质数、卡罗尔数、阶乘数
  • The Deep Learning Compiler: A Comprehensive Survey (深度学习编译器:全面调查)
  • py7zr解压文件时报错CrcError(crc32, f.crc32, f.filename)
  • Kubernetes 入门笔记
  • 磁盘存储链式的 B 树与 B+ 树
  • 数据库原理实验:视图与索引
  • Python训练打卡Day23
  • Biba安全模型详解:守护信息系统完整性的基石
  • 夜读|尊重生命的棱角
  • 融创中国:境外债务重组计划聆讯定于9月15日召开
  • 市场监管总局等五部门约谈外卖平台企业
  • 视频丨美国两名男童持枪与警察对峙,一人还试图扣动扳机
  • 中国人民抗日战争暨世界反法西斯战争胜利80周年纪念活动标识发布
  • 通辽警方侦破一起积压21年的命案:嫌疑人企图强奸遭反抗后杀人