ubuntu – 如何在系统启动时自动启动docker容器?

在系统启动时自动启动docker容器的好方法是什么?

有没有一种在Ubuntu 14.04上执行此操作的首选方法

我过去曾使用supervisord自动启动网络应用程序.但这对Docker来说并不合适.

显然,自动启动Docker容器( from Docker 1.2)的当前方法是使用 restart policies.这将控制Docker在启动时如何处理容器的启动以及在容器退出时如何重新启动容器.到目前为止,我已经使用了’always’选项,并且可以确认它使Docker在系统启动时自动启动容器:
sudo docker run --restart=always -d myimage

文档摘录

Restart Policies Using the –restart flag on Docker run you can
specify a restart policy for how a container should or should not be
restarted on exit.

no – Do not restart the container when it exits.

on-failure – Restart the container only if it exits with a non zero
exit status.

always – Always restart the container regardless of the exit status.

You can also specify the maximum amount of times Docker will try to
restart the container when using the on-failure policy. The default is
that Docker will try forever to restart the container.

06001

This will run the redis
container with a restart policy of always so that if the container
exits,Docker will restart it.

06002

This will run the redis container with a restart policy of on-failure and a maximum restart count of 10. If the redis container exits with a non-zero exit status more than 10 times in a row Docker will abort trying to restart the container. Providing a maximum restart limit is only valid for the on-failure policy.

相关文章

目录前言一、创建Hadoop用户二、更新apt和安装Vim编辑器三、...
原文连接:https://www.cnblogs.com/yasmi/p/5192694.html ...
电脑重启后,打开VirtualBox,发现一直用的虚拟机莫名的消失...
参见:https://blog.csdn.net/weixin_38883338/article/deta...
Ubuntu 18.04 LTS 已切换到 Netplan 来配置网络接口。Netpla...
介绍每个 Web 服务都可以通过特定的 URL 在 Internet 上访问...