Ubuntu sets the docker container as a service

If you need to set the container to start automatically with the system startup, you can make the container start into a service

sudo su -
cd /etc/systemd/system
touch docker-container.service
vim docker-container.service

Write as follows:

[Unit]
Description=Docker Container

[Service]
Restart=always
ExecStart=/bin/bash -c "/usr/bin/docker start -a my-first-container && /usr/bin/docker start -a my-second-container"
ExecStop=/bin/bash -c "/usr/bin/docker stop -t 2 my-first-container && /usr/bin/docker stop -t 2 my-second-container"

[Install]
WantedBy=multi-user.target

Then apply the service

systemctl enable docker-container.service
systemctl startdocker-container.service

Guess you like

Origin blog.csdn.net/majiayu000/article/details/129592675