The Go Blog

autostart docker container

bantana
3 October 2016

/lib/systemd/system/autostart.service

[Unit]
Description=autostart.service
Requires=docker.service
After=docker.service

[Service]
Restart=always
ExecStart=/usr/bin/docker start -a kubernetes
ExecStop=/usr/bin/docker stop -t 2 kubernetes

[Install]
WantedBy=multi-user.target


$ sudo systemctl daemon-reload
$ sudo systemctl enable autostart.service

$ sudo systemctl restart autostart

$ systemctl status autostart
● autostart.service
   Loaded: loaded (/lib/systemd/system/autostart.service; enabled)
   Active: active (running) since Mon 2016-10-03 12:22:13 CST; 14min ago
 Main PID: 729 (docker)
   CGroup: /system.slice/autostart.service
           └─729 /usr/bin/docker start -a kubernetes

Related articles