Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

restart nginx container when upstream servers is updated

Tags:

docker

nginx

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!

like image 209
Hokutosei Avatar asked Oct 10 '14 02:10

Hokutosei


People also ask

Do I need to restart nginx after config change?

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.

Does nginx auto reload config?

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 .

How do I restart a Docker container?

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.


1 Answers

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 
like image 108
Dean Christian Armada Avatar answered Sep 22 '22 15:09

Dean Christian Armada