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!
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/
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 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/
If you want to do this from within a container, you will need service/configuration discovery. Tools like coreOS/etcd and Apache Zookeeper are made to facilitate this process. Fair warning: for simple applications, these can be a bit difficult to manage.
There is also docker-gen, which is somewhat easier to get going. There is even a specific pre-made script for exactly the scenario you are describing.