Supposed I have a Docker container that I want to run, then I can call
$ docker run ...
and everything is fine. Is there a built-in way to run a container in a way that it will be restarted automatically, if the system crashes and reboots?
If so, is this also available in Docker Compose?
If you want the container to be started even if no user has performed a login (like the VirtualBox VM that I only start and don't want to login each time). Here are the steps I performed to for Ubuntu 16.04 LTS. As an example, I installed a oracle db container:
and add the following content:
and enable the service at startup
For more informations https://docs.docker.com/engine/admin/host_integration/
The default restart policy is
no
.For the created containers use
docker update
to update restart policy.0576df221c0b
is the container id.More "gentle" mode from the documentation:
Yes, docker has restart policies such as
docker run --restart=always
that will handle this. This is also available in the compose.yml config file asrestart: always
.