網頁

2017年2月28日 星期二

Docker 1.13.0 --- How to add "restart" policy to the initiating Container if never set it

Since docker 1.11.0 or above version, we can change the restart policy if an initiating container forget to set it.
docker update --restart [Option] [Container ID]
where
        --restart Restart policy to apply when a container exits
 [Option]  
   no         Do not automatically restart the container when it exits. This is the default.
   on-failure[:max-retries] Restart only if the container exits with a non-zero exit status. Optionally, limit the number of restart retries the Docker daemon attempts.
    always          Always restart the container regardless of the exit status. When you specify always, the Docker daemon will try to restart the container indefinitely. The container will also always start on daemon startup, regardless of the current state of the container.
    unless-stopped Always restart the container regardless of the exit status, but do not start it on daemon startup if the container has been put to a stopped state before.

     Note that if the container is started with “–rm” flag, you cannot update the restart policy for it. The AutoRemove and RestartPolicy are mutually exclusive for the container.

As to old version as 1.11.0 before, we can rename the orginial container, start a temp container (but attach the existing volumes of the orginial container), and remove the temp container now that it's no longer needed.
$ docker stop my-old-container
$ docker rename my-old-container my-temp-container
$ docker run  ...  --volumes-from=my-temp-container --restart always myimage
$ docker rm my-temp-container

 To restart the Docker daemon and we can find out the container will start automatically now.


沒有留言:

張貼留言

Since 2010 Design by Davidwa
©Copyright Davidwa Inc. All rights reserved.