Search code examples
dockerdocker-compose

How do I make a Docker container start automatically on system boot?


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?


Solution

  • 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 as restart: always.