Restart Docker container on inner process crash
You can use the --restart flag for docker run commandhttps://docs.docker.com/engine/reference/commandline/run/#restart-policies---restart
Example:docker run --restart=on-failure my-image-name
Or if you are using docker-compose then you restart: on-failure
for the service https://docs.docker.com/compose/compose-file/#restart
When you run multiple services in a container, and you are very, very sure you want this (it's best practice to run a single process in a single container), you may want a process supervisor (for example systemd
) which restart any crashed process inside, or crash if any of it's supervised processes crash.
There are also some other, more lightweight, ways to accomplish this, like a wrapper bash script.
It's all described here: https://docs.docker.com/config/containers/multi-service_container/
Edit after question was updated with Dockerfile:
The easiest way is probably to make sure run.sh
crashes if any of it's subprocesses crash. Then the container will crash, and optionally restart if you use --restart=on-failure
in docker run
.