01/12/2020

How to start Docker Container at boot time

By snorlaxprime

Now that you have all those docker containers working beautifully, there come a point that you will need to restart the server. That’s when all hell break loose because all the dockers container stops working. And you will be like scrambling trying to start them all.

No fear, here is how you can do this using the –restart <value> during the setup. But you didn’t do this, now it is not too late you can check the restart policy using the following command:

sudo docker inspect -f "{{ .HostConfig.RestartPolicy }}" home-assistant

In the example above, I was checking the restart policy of my home-assistant docker container. If you want to know what home-assistant is, you can check out my previous post about installing home-assistant.

In the screen shot above you can see my restart policy is “Always”, if you have a different result showing, such as {no 0}, then you can update the restart policy using the following command:

sudo docker update --restart=always home-assistant

The restart policy can be the following value:

  • no
  • always
  • unless-stopped: always restart unless explicitly stopped.

Now that you have updated the restart policy, it is time to test it out. You can restart the server using the following command.

sudo shutdown -r now

If all well, all your docker containers should restart as per the restart policy that you have setup.

There are more alternative you can use such as Init System. The following blog post describe it in details.

https://toub.es/2017/08/08/how-to-start-a-docker-container-at-boot-time/

I hope the above article helps to reduce your stress during reboot.