Search code examples
dockersystemdrebootdocker-container

Docker container doesn't start after reboot with enabling systemd script


I have the following systemd script:

[Unit]
Description=Hub docker container
After=docker.service

[Service]
User=root
ExecStart=/home/hub/hub.sh
ExecStop=/bin/docker stop hub
ExecStopPost=/bin/docker rm hub

[Install]
WantedBy=multi-user.target

Running the command: systemctl start/stop hub works fine. I also created the symlink by using systemctl enable hub. Why doesn't my service start up after I reboot the entire laptop? I followed the docker guide so that Docker starts up on reboot, but for some reason my container doesn't start up. Am I missing a field in my script?

The command I am using my ExecStart, "/home/hub/hub.sh" script is:

docker run --net=host --restart=always --name hub -t hub

After reboot I get the following when I type systemctl status hub:

● hub.service - Hub docker container
   Loaded: loaded (/etc/systemd/system/hub.service; enabled; vendor preset: disabled)
   Active: inactive (dead)

Solution

  • In order to start container after reboot you need to add this property: --restart=always to your container start script. For example: docker run -d -p 80:5000 --restart=always image_name