restart nginx container when upstream servers is u

2020-05-20 07:29发布

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!

标签: nginx docker
4条回答
趁早两清
2楼-- · 2020-05-20 07:31

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
查看更多
Juvenile、少年°
3楼-- · 2020-05-20 07:48

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.

查看更多
叛逆
4楼-- · 2020-05-20 07:50

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/

查看更多
Lonely孤独者°
5楼-- · 2020-05-20 07:51

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/

查看更多
登录 后发表回答