Home > Software design >  How to restart nginx service in Docker nginx image (`service nginx restart`) without container stopp
How to restart nginx service in Docker nginx image (`service nginx restart`) without container stopp

Time:09-23

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?

CodePudding user response:

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

CodePudding user response:

nginx -t to check config is good

nginx -s reload to reload config without restart

  • Related