I am writing this tech snippet based on my experience of rebooting a machine where docker server is installed. My requirement was to enable auto restart of the docker container even after the system reboots.

If we reboot the machine, all the services in the machine will get stopped and during the restart, only the services that are configured with auto-restart will only start. To start all the docker containers on system reboot, we need to ensure the following things.

1. Ensure docker daemon restarts on system reboot.

The below command works on CentOS/ RHEL and Ubuntu.

sudo systemctl enable docker.service

2. Ensure the docker container has restart policy configured.

docker update --restart=always [container id or container name]