Docker autostart container

Create service

make file in /etc/systemd/system/

cd /etc/systemd/system
nano /docker-[containername].service

Insert following code:

[Unit]
Description=Docker [containername] server
Requires=docker.service
After=docker.service
[Service]
Restart=always
ExecStart=/usr/bin/docker start -a [containername]
ExecStop=/usr/bin/docker stop -t 2 [containername]
[Install]
WantedBy=default.target

Add service to systemd

systemctl enable docker-[containername].service

When system reboots, service will be started.

Comments

Leave a Reply