Docker: how to restart process inside of container

2019-03-16 01:11发布

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

标签: docker
3条回答
对你真心纯属浪费
2楼-- · 2019-03-16 01:22

you need to use an entrypoint shell script you will need to build your docker file so that you can copy the files in to the container.

your entrypoint.sh or call it runjettytests.sh

pseudo code for that will look like:

#!/bin/sh
java -jar start.jar
$runTests
java -DSTOP.PORT=8080 -DSTOP.KEY=stop_jetty -jar start.jar --stop
cp dataset2 data/
java -jar start.jar
$runTests2
java -DSTOP.PORT=8080 -DSTOP.KEY=stop_jetty -jar start.jar --stop
exit(0)

clearly your use case may vary but thats a rough idea

查看更多
聊天终结者
3楼-- · 2019-03-16 01:45

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>
查看更多
地球回转人心会变
4楼-- · 2019-03-16 01:45

Enter the container and restart it.

Manual Way:

docker exec -it <containeridorname> /bin/bash

Or Automated Way:

docker exec -it <containeridorname> /restartjettycommand.sh
查看更多
登录 后发表回答