资讯专栏INFORMATION COLUMN

(学习到实践)六、docker自定义nginx/openresty

BingqiChen / 2605人阅读

摘要:但官方没有发布相关东西,所以以结合安装参考官方的为原则编写。运行测试运行成功,大小,太大了感觉,提交到云端。启动官方镜像提交到云端,偶然想搜索下有没有,竟然反问有官方镜像,了个下来,还不错。

前言 为什么要使用openresty?

官方说明:OpenResty® 是一个基于 Nginx 与 Lua 的高性能 Web 平台,其内部集成了大量精良的 Lua 库、第三方模块以及大多数的依赖项。所以。
但openresty官方没有发布docker相关东西,所以以:结合openresty安装、参考docker-nginx官方的为原则编写。

1.依赖安装测试

官方声明依赖:perl 5.6.1+, libpcre, libssl

a.按nginx镜像测试
# perl查找
/ # apk search perl5
perl-5.26.3-r0  #就一个可选

/ # apk search libpcre
libpcre2-32-10.32-r1 #貌似最新版本了,32位的?
pcre-dev-8.42-r1
libpcre2-16-10.32-r1
pcre2-dev-10.32-r1
libpcre16-8.42-r1
libpcre32-8.42-r1
pcre2-10.32-r1
pcre-8.42-r1
libpcrecpp-8.42-r1

/ # apk search libssl
openssl-dev-1.1.1b-r1
libressl-dev-2.7.5-r0  #看起来最合适
nss-3.41-r0
libssl1.1-1.1.1b-r1
dovecot-2.3.6-r0
libressl2.7-libssl-2.7.5-r0

/ # apk add perl-5.26.3-r0 libpcre2-32-10.32-r1 libressl-dev-2.7.5-r0
# 完全报错,这个alpine依赖搞不了,官方https://pkgs.alpinelinux.org/包的搜索页捉襟见肘,不得不放弃“小而美”。
b.容器测试

参考官方选则debian,github上构建平台镜像的许多镜像选择stretch-slim精简版的,看下大小最新的只有55.3M,比较满意。
环境安装测试:

[]:~/tmp/dk/openresty# docker run -itd --name df -v /root/tmp/dk/openresty:/tmp/host debian:stretch-slim
[]:~/tmp/dk/openresty# docker exec df -it /bin/bash

初始安装清华源,切换百度源(云本机),apt-get update超慢,后回归官源,后期卡死用网易源。
问题:
1、./configure: error: ngx_postgres addon was unable to detect version of the libpq library.

apt-get libpq-dev -y

2、./configure: error: the HTTP gzip module requires the zlib library.

apt-get install openssl libssl-dev libperl-dev -y
apt-get install zlib1g-dev -y

到此OK。

c.第一步通过的代码
FROM debian:stretch-slim

#MAINTAINER 维护者信息
MAINTAINER cffycls@foxmail.com
ENV RESOURCE "
deb http://mirrors.163.com/debian/ stretch main non-free contrib 

deb http://mirrors.163.com/debian/ stretch-updates main non-free contrib 

deb http://mirrors.163.com/debian/ stretch-backports main non-free contrib 

deb-src http://mirrors.163.com/debian/ stretch main non-free contrib 

deb-src http://mirrors.163.com/debian/ stretch-updates main non-free contrib 

deb-src http://mirrors.163.com/debian/ stretch-backports main non-free contrib 

deb http://mirrors.163.com/debian-security/ stretch/updates main non-free contrib 

deb-src http://mirrors.163.com/debian-security/ stretch/updates main non-free contrib 
"
ENV VERSION 1.15.8.1

# !!!注意字符串变量、转义自动解析
RUN echo $RESOURCE > /etc/apt/sources.list && cat /etc/apt/sources.list 
    && apt-get update 
    && apt-get install libpcre3-dev libssl-dev perl make build-essential curl 
        -y

COPY openresty-$VERSION.tar.gz /tmp/openresty.tar.gz
RUN groupadd -r openresty && useradd -r -g openresty openresty 
    # && curl  
    && mkdir -p /usr/src && cd /usr/src && mv /tmp/openresty.tar.gz ./ 
    && tar -zxf openresty.tar.gz --strip-components 1 
    && ./configure 
           --prefix=/usrl/ocal/openresty 
           --with-luajit 
           --without-http_redis2_module 
           --with-http_iconv_module 
           --with-http_postgres_module 
    
    && make -j "$(nproc)" 
    && make install 
    && rm -rf /usr/src
# COPY nginx.conf /etc/nginx/nginx.conf
# COPY nginx.vh.default.conf /etc/nginx/conf.d/default.conf
# COPY vhost.conf /etc/nginx/conf.d/vhost.conf
VOLUME ["/etc/nginx","/var/www/html"]

EXPOSE 80
STOPSIGNAL SIGTERM

# CMD ["nginx", "-g", "daemon off;"] #注意官方提示
2.运行测试

准备配置数据(之前旧配置),注意 html和nginx文件夹 的参数共享:

[]:~/tmp/dk/openresty# tree ./
./
├── config
│   ├── conf.d
│   │   └── nginx.vh.default.conf
│   │   └── vhost.conf
│   └── nginx.conf
└── html
a.测试启动

测试容器df(手动搭建,系统无法ps),运行正常:

root@df08a646aaa0:/# nginx
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

但Dockerfile所建镜像的容器启动关闭无日志,更换openresty官方配置:

[]:~/tmp/dk/openresty# docker run -itd --name n1 -v /root/tmp/dk/openresty/config:/etc/nginx 
    -v /root/tmp/dk/openresty/html:/var/www/html cffycls/openresty:0.9 
     /usrl/ocal/openresty/nginx/sbin/nginx 
#无法启动,容器运行终止,无日志。应该是配置文件问题
b.修改配置文件

使用官方原包未修改:

# 官包解压路径:./bundle/nginx-1.15.8/conf/nginx.conf
[]:~/tmp/dk/openresty# tree conf
conf
├── fastcgi.conf
├── fastcgi_params
├── koi-utf
├── koi-win
├── mime.types
├── nginx.conf
├── scgi_params
├── uwsgi_params
└── win-utf

去掉run加的命令,加上端口,运行Up了。

c.运行测试
CMD ["/usrl/ocal/openresty/nginx/sbin/nginx", "-g", "daemon off;"]
[]:~/tmp/dk/openresty# docker run -itd --name n1 -p 80:80 
    -v /root/tmp/dk/openresty/conf:/usrl/ocal/openresty/nginx/conf 
    -v /root/tmp/dk/openresty/html:/usrl/ocal/openresty/nginx/html 
    openresty/openresty:1.0

运行成功,大小357M,太大了感觉,提交到云端。

3.启动官方镜像

提交到云端,偶然想搜索下有没有,docker-hub竟然(反问)有官方镜像,pull了个下来,144M还不错。真是重复造轮子了!!!
折腾半天,算是个教训了,算是测得到了运行方法,结果也还行。

[]:~/tmp/dk/openresty# docker run -itd --name n1 -p 80:80 
    -v /root/tmp/dk/openresty/conf:/usrl/local/openresty/nginx/conf 
    -v /root/tmp/dk/openresty/html:/usr/local/openresty/nginx/html 
    openresty/openresty

访问web端正常。

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/40514.html

相关文章

  • Rancher v1.2基础设施引擎整体架构分析

    摘要:官方于月日发布了其容器部署与管理平台的最新版本,。架构总览在版本的整体架构图如下图所示上,引擎向下深入演化成了基础设施引擎,这一点上在时代也早有体现。基础设施引擎初次安装版本,会发现多了如下图所示的明显标识,默认的引擎需要安装等服务。 Rancher Labs官方于12月1日发布了其容器部署与管理平台Rancher的最新版本,Rancher v1.2。Rancher v1.2可以说是一...

    Sike 评论0 收藏0
  • Rancher v1.2基础设施引擎整体架构分析

    摘要:官方于月日发布了其容器部署与管理平台的最新版本,。架构总览在版本的整体架构图如下图所示上,引擎向下深入演化成了基础设施引擎,这一点上在时代也早有体现。基础设施引擎初次安装版本,会发现多了如下图所示的明显标识,默认的引擎需要安装等服务。 Rancher Labs官方于12月1日发布了其容器部署与管理平台Rancher的最新版本,Rancher v1.2。Rancher v1.2可以说是一...

    tianhang 评论0 收藏0
  • NginxOpenresty增加waf配置

    摘要:说明防止注入,本地包含,部分溢出,测试,等攻击防止备份之类文件泄漏防止之类压力测试工具的攻击屏蔽常见的扫描黑客工具,扫描器屏蔽异常的网络请求屏蔽图片附件类目录执行权限防止上传下载使用使用安装下载解压后,将整放到目录中,并命名为配置安装路径假 1. Ngx lua waf 说明 防止sql注入,本地包含,部分溢出,fuzzing测试,xss,SSRF等web攻击防止svn/备份之类文件泄...

    CoderDock 评论0 收藏0
  • Docker学习之路()用commit命令创建镜像

    摘要:邮件激活后,可以测试登录这条命令会完成登录,并将认证信息报错起来供后面使用。所以先用命令退出容器,再运行命令命令中,指定了要提交的修改过的容器的目标镜像仓库镜像名。提交的知识创建容器的镜像与容器的当前状态之间的差异部分,很轻量。 假期快要结束了,干点正事,接着Docker的学习。 构建镜像 构建镜像的两种方法: 使用docker commit 命令 使用docker build...

    KoreyLee 评论0 收藏0
  • Nginx(openresty)安装

    摘要:安装包准备准备好源码包解压执行以下命令解压安装包编译安装执行以下命令安装编译所需的依赖执行以下命令编译安装就成功安装到了 安装包准备 准备好openresty源码包: /opt/ngx_openresty-1.9.3.2.tar.gz 解压 执行以下命令解压安装包: cd /opt tar zxvf ngx_openresty-1.9.3.2.tar.gz 编译安装 执行以下命令安...

    vpants 评论0 收藏0

发表评论

0条评论

最新活动
阅读需要支付1元查看
<