Docker Community Forums

Share and learn in the Docker community.

Removing container if the java instance running in it shuts down


(Welankar) #1

Hi

I am new to Docker and I was trying out a particular scenario for which I do not find any solution online or on forums.

The details on my setup is such that, I am using Docker 17.06 .1-ee-2 on Linux with a Swarm setup. I have a container which contains a Java process. As a program functionality, we shutdown the running Java program based on a few conditions so as to avoid further damage to the data and consistency of our program. Once detected that the Java program has gone down we manually bring it up by doing docker stack deploy.

My question was whether there is any functionality / signal / setting available in Docker which will kill the Container (self-destroy or self-rm) once its detects that the Java program running within it has shut down?

Currently, if the Java process has gone down, we can still see the Docker container in docker service ls which seems misleading because if the only process within the Container is not running then the Container should ideally be rm’ed as well or there should at least be a way to do it.

Thoughts / Pointers?

thanks!


(Sam) #2

make the java process THE entrypoint command… when it ends, the container shuts down


(Welankar) #3

@sdetweil - Thanks for your pointer. Yes that was there already but got from our docker team member that they had added another process over there which used sleep 10d to make the logs available for debug and analysis purposes even after the container is shutdown. That process was removed from the container and we moved the logs to external location and we can now the functionality of container closing itself once the java process is shut down.

Just for the record, the command docker service ls still shows the service which had the Java container in the result listing but doing a docker ps does not show that container (which proves it gets auto-killed) as expected. This serves our purpose as we now just do a docker stack deploy again and only those services in the stack which were killed / shut down get restarted from entry-point (as expected) and the rest of the services are untouched.