- 发布于
修改配置文件自动热更新的nginx镜像
1231-–
- 作者
- 姓名
- zhli
- 修改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"]
- 使用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;"