Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker: how to restart process inside of container?

Tags:

docker

I have a set of tests which I would like to run on docker container. In the middle of the tests I am changing me test data and I need to restart JETTY.

What is the best way to do that?

I can imagine some options:

  1. With SSH - but for the docker ssh is not the best option.

  2. Python agent on docker to listen sockets - expose one more port, connect and restart jetty.

Maybe there are better ideas for that?

Thanks

like image 246
SergiiKozlov Avatar asked Jan 14 '15 16:01

SergiiKozlov


People also ask

How do I restart docker without stopping containers?

Restart the Docker daemon. On Linux, you can avoid a restart (and avoid any downtime for your containers) by reloading the Docker daemon. If you use systemd , then use the command systemctl reload docker . Otherwise, send a SIGHUP signal to the dockerd process.

What happens when you press Ctrl P Q inside the container in docker?

Run Hub docker container Note that pressing `Ctrl+C` when the terminal is attached to a container output causes the container to shut down. Use `Ctrl+PQ` in order to detach the terminal from container output.


2 Answers

Sounds like the process you're trying to restart is the primary process for the docker container (ie. the one you set in your Dockerfile if you have one, and when you run 'ps -ef' inside the container you would see the PID for your process set to 1). If this is the case, then you cannot restart it from inside the container. You should just restart the container itself:

docker restart <container_id>
like image 159
Rob Bailey Avatar answered Sep 17 '22 23:09

Rob Bailey


Enter the container and restart it.

Manual Way:

docker exec -it <containeridorname> /bin/bash

Or Automated Way:

docker exec -it <containeridorname> /restartjettycommand.sh
like image 39
user2105103 Avatar answered Sep 18 '22 23:09

user2105103