logo
发布于

修改配置文件自动热更新的nginx镜像

1231-–
作者
  • avatar
    姓名
    zhli
  1. 修改Dockerfile,并安装inotify-tools
Dockerfile
FROM nginx:stable-alpine

COPY auto-reload-nginx.sh /home/auto-reload-nginx.sh

RUN chmod +x /home/auto-reload-nginx.sh

RUN apk add inotify-tools

ENTRYPOINT ["/home/auto-reload-nginx.sh"]
  1. 使用inotifywait监听配置文件夹/etc/nginx/conf.d/
auto-reload-nginx.sh
#!/bin/sh
inotifywait -e modify,move,create,delete -m --timefmt '%d/%m/%y %H:%M' --format '%T' \
/etc/nginx/conf.d/ | while read date time; do
	
    echo "At ${date} ${time}, config file update detected."
    nginx -t && nginx -s reload

done &

nginx -g "daemon off;"