Automatically restart process on crash in an Ubuntu docker container

366 Views Asked by At

I have a process in an Ubuntu docker container. If it crashes, I want to restart it automatically. What is the best way to go about it? I checked systemd (which is the normal Linux method) but docker doesn't support it. inittab is also deprecated.

1

There are 1 best solutions below

0
leopal On

Docker offers such functionality, all you have to do is to define a restart policy for the container.

You should choose one of the available policies no,always,on-failure,unless-stopped and adjust your docker run command accordingly.

From docs:

To configure the restart policy for a container, use the --restart flag when using the docker run command

For your case, choose one of always or on-failure.

Note: The above is valid only if the process you have mentioned is the container's entrypoint.