docker容器自启动方法

docker 容器自启动方法

在启动容器时加上参数 --restart=always

docker run -it -p 8550:8545  -p 30305:30303 --name=eth-node --restart=always -v /home/sungrow_ethereum:/ethereum-test --entrypoint /ethereum-test/node/init.sh ethereum/client-go:v1.8.12 /ethereum-test/node/node.sh

对于已经启动运行中的docker容器,则使用update更新:

docker update --restart=always container_id

ps:
Docker容器的重启策略如下:

  • no,默认策略,在容器退出时不重启容器
  • on-failure,在容器非正常退出时(退出状态非0),才会重启容器
  • on-failure:3,在容器非正常退出时重启容器,最多重启3次
  • always,在容器退出时总是重启容器
  • unless-stopped,在容器退出时总是重启容器,但是不考虑在Docker守护进程启动时就已经停止了的容器

查看容器重启次数

docker inspect -f "{
    
    { .RestartCount }}" container_id

查看容器最后一次的启动时间

docker inspect -f "{
    
    { .State.StartedAt }}" container_id

猜你喜欢

转载自blog.csdn.net/qq_43314560/article/details/115300569
今日推荐