Restart nginx container when updating upstream servers

I want to add / remove servers in my nginx running inside docker container

I use the ADD command in the Dockerfile to add my nginx.conf to the / etc / nginx directory.

# Copy a configuration file from the current directory ADD nginx.conf /etc/nginx/ 

then in my running nginx container that has this configuration

 # 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 to restart my nginx to take effect the edited nginx.conf?

Thank you in advance!

+5
source share
4 answers

to reload the NGINX configuration, run the command

docker kill -s HUP container_name

https://blog.docker.com/2015/04/tips-for-deploying-nginx-official-image-with-docker/

+9
source

restarting the container is not recommended when initializing Docker Swarm, as it can remove the nginx service. Therefore, if you need an alternative to docker restart ; You can enter the container and just run nginx -s reload

For example, in docker env, if you have a container named nginx

 docker exec <nginx_container_id> nginx -s reload 
+19
source

If you want to restart the NGINX process, restart the container by running the command:

 docker restart <container name> 

https://blog.docker.com/2015/04/tips-for-deploying-nginx-official-image-with-docker/

+2
source

If you want to do this from a container, you will need a service / configuration discovery. Tools such as coreOS / etcd and Apache Zookeeper are made to facilitate this process. Fair warning: for simple applications this can be difficult to handle.

There is also docker-gen , which is somewhat easier to obtain. There is even a specific pre-made script for the exact script that you are describing.

+1
source

Source: https://habr.com/ru/post/1204391/


All Articles