Home > Operation and Maintenance > Docker > How to start a docker container automatically after booting

How to start a docker container automatically after booting

王林
Release: 2020-03-23 18:13:55
Original
3405 people have browsed it

How to start a docker container automatically after booting

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
Copy after login

--restart The specific parameter value details are as follows:

no - 容器退出时,不重启容器
on-failure - 只有在非0状态退出时才从新启动容器
always - 无论退出状态是如何,都重启容器
Copy after login

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
Copy after login

If --restart=always is not specified when creating, you can use the update command

docker update --restart=always xxx
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template