itinneed
itinneed

Reputation: 153

Restart a service in a docker container

I have a docker container that runs nginx on debian. In response to some input, I need to restart the nginx service but not the whole container. Running "service nginx restart" blows the whole container away.

Is there any way to restart a service in a docker container without restarting the whole container?

Upvotes: 0

Views: 4732

Answers (3)

ndotie
ndotie

Reputation: 2150

Since there is no direct access to the command line of the NGINX container, NGINX commands cannot be sent to a container directly. Instead, signals can be sent to a container via Docker kill command.

To reload the NGINX configuration, send the HUP signal to Docker:

$ docker kill -s HUP container-name

To restart NGINX, run this command to restart the container:

$ docker restart container-name

Upvotes: 0

Saeed
Saeed

Reputation: 4125

Of course it's recommended to rebuild the container when you do the changes, but I recommend reloading the nginx service with either running bash inside of container and then reload it:

sudo docker exec -it NGINX_NAME bash

Then run service nginx reload.

Or:

sudo docker exec -it NGINX_NAME service nginx reload

Upvotes: 1

You can go inside the container and restart the nginx

sudo docker exec –it nginx-container /bin/bash

Upvotes: 1

Related Questions