When using docker run to start the container, use the --restart parameter to set:
docker run -m 512m --memory-swap 1G -it -p 6379:6379 --restart=always --name redis -d redis
--restart The specific parameter value details are as follows:
no - 容器退出时,不重启容器 on-failure - 只有在非0状态退出时才从新启动容器 always - 无论退出状态是如何,都重启容器
You can also specify the maximum number of times Docker will try to restart the container when using the on-failure policy.
By default, Docker will try to restart the container forever.
sudo docker run --restart=on-failure:10 redis
If --restart=always is not specified when creating, you can use the update command
docker update --restart=always xxx
Recommended related tutorials: docker tutorial
The above is the detailed content of How to start a docker container automatically after booting. For more information, please follow other related articles on the PHP Chinese website!