Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to restart nginx service in Docker nginx image (`service nginx restart`) without container stopping?

I've been experimenting with nginx using Docker image nginx.

docker run -d --name nginx nginx
docker exec -ti nginx bash
# <edit /etc/nginx/conf.d files>

Now in order to load the edited /etc/nginx/conf.d files, I execute service nginx restart, which causes the container to stop, since the init process (nginx) terminated. Thus, I need to execute docker start nginx and docker exec -ti nginx bash to resume.

Is there any way to restart nginx to have it load the edited config files without also stopping the container?

like image 291
Shuzheng Avatar asked Sep 08 '25 03:09

Shuzheng


2 Answers

Call NGINX again with the -s command line parameter.

For example, /usr/bin/nginx -s stop will stop the NGINX server.

the other signals using with -s command are:

  • stop
  • quit
  • reopen
  • reload

The reload command keeps the Nginx server running as it reloads updated configuration files. If Nginx notices a syntax error in any of the configuration files, the reload is aborted and the server keeps running based on old config files. Reloading is safer than restarting Nginx.

example: /usr/bin/nginx -s reload

like image 108
Ismael Clemente Aguirre Avatar answered Sep 09 '25 22:09

Ismael Clemente Aguirre


nginx -t to check config is good

nginx -s reload to reload config without restart

like image 32
Def Soudani Avatar answered Sep 09 '25 23:09

Def Soudani