I want to add/remove servers in my nginx running inside a docker container
I use ADD command in Dockerfile to add my nginx.conf to /etc/nginx dir.
# Copy a configuration file from the current directory ADD nginx.conf /etc/nginx/
then in my running nginx container that have a conf like this
# List of application servers upstream app_servers { server 172.17.0.91:9000; server 172.17.0.92:9000; server 172.17.0.93:9000; }
how do restart my nginx to take effect of the edited nginx.conf?
thank you in advance!
You need to reload or restart Nginx whenever you make changes to its configuration. The reload command loads the new configuration, starts new worker processes with the new configuration, and gracefully shuts down old worker processes.
nginx -t will test the syntax of the configuration files and ensure that all configuration files referenced are accessible. If the Nginx configuration passes testing, then Nginx will be reloaded with nginx -s reload .
Docker also lets the user set the restart policy upon exit or failure. Users can type docker ps to check if the restart policy is active; it will be shown as either Up , when the container is up and running, or Restarting when the container is in the restart state.
restarting the container is not advisable when you initialize Docker Swarm because it may remove the nginx service. So if you need an alternative aside docker restart
; You can go inside the container and just run nginx -s reload
For example, in docker env, if you have the container named nginx
docker exec <nginx_container_id> nginx -s reload
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With