How to set up automatic container restart in Docker?

In order to set Docker to automatically restart containers, you can use the –restart option to specify the container’s restart policy. Here are some commonly used restart policies:

  1. always restart
  2. –restart=if-not-stopped
  3. Automatically restart in case of failure.

For example, to always automatically restart the container on exit, you can use the following command to start the container:

docker run --restart=always [其他选项] 镜像名称

To change the restart policy of an existing container, you can use the docker update command.

docker update --restart=always 容器名称

Please note that these settings will only take effect while the container is running, if you want to permanently save these settings, you can write them into the Docker Compose file or Docker Swarm service configuration.

广告
Closing in 10 seconds
bannerAds