├── .gitignore ├── Dockerfile ├── README.md └── entrypoint.sh /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM nginx:latest 2 | 3 | # Install inotify-tools to watch file changes 4 | RUN apt-get update && apt-get install -y inotify-tools 5 | 6 | # Add our custom entrypoint script 7 | COPY entrypoint.sh /entrypoint.sh 8 | RUN chmod +x /entrypoint.sh 9 | 10 | ENTRYPOINT ["/entrypoint.sh"] 11 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # nginx-reloaded 2 | 3 | `nginx-reloaded` is a simple and straightforward alternative to the default nginx Docker image which adds support for automatic silent reloads anytime `nginx.conf` is updated. 4 | 5 | By providing a thin layer on top of the standard nginx:latest this image leverages inotify to watch the conf file and run silent reloads in the background on changes without using a sidecar or other complicated workarounds. It was primairly designed to run in Kubernetes environments that use a ConfigMap to mount and update server configuration. 6 | 7 | ## Features 8 | 9 | - **Automatic Silent Reload**: With the help of `inotify-tools`, nginx can detect changes in the `nginx.conf` and reload without any disruption. 10 | - **Minimalistic Design**: Built on top of the official nginx Docker image, `nginx-reloaded` is lightweight and straightforward. 11 | - **Custom Path Support**: You can specify a custom path for `nginx.conf` using the `NGINX_RELOADED_PATH` environment variable. 12 | 13 | ## Quick Start 14 | 15 | To get started with `nginx-reloaded`, ensure you have Docker installed and running. 16 | 17 | 1. **Build the Docker image**: 18 | 19 | ```bash 20 | docker build -t nginx-reloaded:latest . 21 | ``` 22 | 23 | 2. **Run the Docker container**: 24 | 25 | ```bash 26 | docker run -d --name nginx-reloaded-container nginx-reloaded:latest 27 | ``` 28 | 29 | ## Custom Configuration 30 | 31 | To provide your custom `nginx.conf` mount it to `/etc/nginx/nginx-reloaded/nginx.conf` when running your container. 32 | 33 | ```bash 34 | docker run -d --name nginx-reloaded-container -v /path/to/your/nginx.conf:/etc/nginx/nginx-reloaded/nginx.conf nginx-reloaded:latest 35 | ``` 36 | 37 | ### Specifying a Custom Path 38 | 39 | To use a custom path for `nginx.conf`, set the `NGINX_RELOADED_PATH` environment variable when running the Docker container. 40 | 41 | ```bash 42 | docker run -d --name nginx-reloaded-container -e NGINX_RELOADED_PATH=/path/to/your/nginx.conf nginx-reloaded:latest 43 | ``` 44 | 45 | ## Behind the Scenes 46 | 47 | The magic behind the auto-reloading feature is `inotify-tools`. When the `nginx.conf` undergoes changes like modifications or deletion, the `inotifywait` loop detects these alterations and reloads nginx. 48 | 49 | For further details, refer to the provided Dockerfile and entrypoint.sh. 50 | 51 | ## Contributions & Support 52 | 53 | This project is designed and maintained by Eflyn. Contributions, feedback, and issues are welcome. 54 | -------------------------------------------------------------------------------- /entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Get NGINX_RELOADED_PATH from ENV or set to default 4 | CONFIG_PATH=${NGINX_RELOADED_PATH:-'/etc/nginx/nginx-reloaded/nginx.conf'} 5 | 6 | # Start the inotifywait loop in the background 7 | while inotifywait -e modify,delete_self,move_self $CONFIG_PATH; do 8 | echo "Detected changes in nginx.conf. Reloading nginx..." 9 | nginx -s reload 10 | done & 11 | 12 | # Start Nginx in the foreground with the custom config 13 | exec nginx -g "daemon off;" -c $CONFIG_PATH --------------------------------------------------------------------------------