Using --restart=always policy will handle restarting existing containers in the event of a reboot.
The problem is that if there are several containers with --restart=always when you start the image of a newer version, as discussed in Docker, how do I turn off the automatic restart of the container? ,
Attempting to automatically delete a container when it exists using the docker run --rm path selection option will also lead to problems with --restart=always because they conflict with each other .
$ docker run --rm --restart always <image> Conflicting options: --restart and --rm
Therefore, in this case, it is better to choose another option: --restart if the policy is not stopped .
$ docker run --rm --restart unless-stopped <image>
This policy will not conflict with docker run --rm but as explained in the docker documentation :
This is similar to --restart=always , except that when the container stops (manually or otherwise) , it does not restart even after restarting the Docker daemon.
Thus, when using this --restart unless-stopped , to make sure that the restart works if it accidentally stops when you close the terminal, run it once in another terminal, as shown below:
$ docker ps $ docker restart <container>
Wait for the destruction process to complete in the previous shell, then close it and just exit ( do not exit ).
And once again check in the remaining terminal if the container is working:
$ docker ps
If it still works, you can safely restart the computer and check again that the application is restarting, and see that your docker is clean, without using multiple containers.
Chetabahana Mar 13 '19 at 8:08 2019-03-13 08:08
source share