可根据配置文件变化自动reload的openresty docker镜像制作
admin
2023-03-29 21:21:10
0

1.      创建工作目录

mkdir openresty && cd openresty

2.      编写使用inotify监控配置文件变化并自动reload的脚本auto-reload.sh:

#!/bin/sh
inotifywait -e modify,move,create,delete -mr --timefmt '%d/%m/%y %H:%M' --format '%T %f %e' \
/usr/local/openresty/nginx/conf/conf.d | while read event; do
    echo "$event"
    /usr/local/openresty/nginx/sbin/nginx -s reload
done

3.      编写镜像启动脚本start.sh:

#!/bin/bash
/usr/bin/openresty -g "daemon off;" &
/auto-reload.sh

4.      编写配置文件nginx.conf:

user nobody;
worker_processes  auto;
#worker_cpu_affinity 01 10;
worker_rlimit_nofile 65535;
events {
    use epoll;
    worker_connections  60000;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    tcp_nodelay   on;
    log_format  main  '$status $host $remote_addr $request_time - '
                      '$upstream_status $upstream_addr $upstream_response_time '
                      '[$time_local] $request '
                      '$bytes_sent $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
    access_log /usr/local/openresty/nginx/logs/access.log main;
    error_log /usr/local/openresty/nginx/logs/error.log;
    log_not_found  off;
    sendfile        on;
    keepalive_timeout  15;
    server_names_hash_bucket_size 4096;
    client_header_buffer_size 16k;
    large_client_header_buffers 4 64k;
    gzip on;
    gzip_http_version 1.0;
    gzip_proxied     expired no-cache no-store private auth;
    gzip_types       text/plain application/x-javascript text/css  application/xml text/javascript;
    gzip_min_length  1000;
    gzip_comp_level 5;
    gzip_buffers    4 8k;
    gzip_disable "MSIE [1-6]\.(?!.*SV1)";
    include localenv.d/*.conf;
    include env.d/*.conf;
    include conf.d/*.backend.cfg;
    include conf.d/*.server.cfg;
    server {
        listen       80;
        server_name  localhost;
        #access_log  logs/host.access.log  main;
        location / {
            root   html;
            index  index.html index.htm;
        }
        #error_page  404              /404.html;
        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

5.      编写dockerfile:

FROM centos:7.6.1810
 
MAINTAINER openresty1.15.8.2 
 
ADD auto-reload.sh auto-reload.sh
ADD start.sh start.sh
RUN yum -y install epel-release && yum install inotify-tools -y && yum install -y yum-utils && yum-config-manager --add-repo https://openresty.org/package/centos/openresty.repo && yum install -y openresty && yum clean all && chmod +x start.sh && chmod +x auto-reload.sh
ADD nginx.conf /usr/local/openresty/nginx/conf/nginx.conf
EXPOSE 80
EXPOSE 443
CMD ["./start.sh"]

6.      执行docker build命令:

docker build -t openresty:1.15.8.2 -f ./dockerfile .

上述命令执行完后,就可以通过docker images看到刚制作好的openresty镜像了

7.      验证,用以下命令运行容器:

docker run -itd -p 8080:80 -v /data/logs:/usr/local/openresty/nginx/logs -v /data/nginx/conf.d:/usr/local/openresty/nginx/conf/conf.d openresty:1.15.8.2

在宿主机目录/data/nginx/conf.d下新增或修改配置文件,容器中的openresty会自动reload,镜像制作成功。


相关内容

热门资讯

特朗普下令不打了,美国的“余粮... 可以说戛然而止,快得让很多人都无法适应。前两周,每一天美国都要打击伊朗一通。就在7月24日白宫会议前...
穆杰塔巴最新表态:支持黎真主党 △伊朗最高领袖穆杰塔巴·哈梅内伊(资料图)当地时间7月26日晚,伊朗最高领袖穆杰塔巴·哈梅内伊对黎巴...
美军瘫痪一艘驶向伊朗的油轮,特... 美国总统特朗普虽下令暂停打击伊朗,但美军仍在执行对霍尔木兹海峡的封锁任务。针对美军瘫痪一艘驶向伊朗油...
“小牌大耍”的底气到底是哪里来... 澎湃首席评论员 李平这两天,“艺人李权哲乘高铁占座事件”在网上引发热议,该艺人参加的活动主办方曾发布...
越南籍船舶南海遇险沉没,中方已... 据凤凰卫视报道,一艘越南船舶7月24日夜间在越南庆和以东220海里附近遇险沉没,船上共62名越南籍人...
李权哲占座、蒙面、装死:娱乐圈... 你买了一张高铁一等座的票,找到自己的位置,18A。有人坐着。你拿出手机看了眼购票记录——没错,18A...
杭州景区咖啡店闯入1条幼蛇,仅... 夏天气温高、湿度大,蛇类活动进入高峰期,千万别被“小蛇无害”的刻板印象骗了!有些幼蛇看着迷你可爱,实...
AI开源公开信签署企业增至50... IT之家 7 月 26 日消息,英伟达、微软、IBM、Meta 等 25 家美国科技企业本周(7 月...
南阳快手短视频代运营企业的服务... 在短视频平台快速发展的背景下,企业通过快手等渠道进行内容运营已成为常见的市场动作。对于希望借助短视频...
普通人该如何跟上科技发展的步伐 这个被称作科技的词汇, 听起来既有宏大之感, 又颇为遥远, 好似仅仅归属于在实验室里专心致志钻研的科...