> For the complete documentation index, see [llms.txt](https://close.gitbook.io/yun-wei-bi-ji/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://close.gitbook.io/yun-wei-bi-ji/centos/docker/docker-rong-qi-zi-dong-qi-dong-she-zhi.md).

# Docker容器自动启动设置

**设置已停止的容器自启动**

```bash
 # 若容器全部没有开启自启动，----> 开启自启
 docker ps -a |awk '/Exited/ {print $NF}' |xargs docker update --restart=always
 docker ps -a |awk '/Exited/ {print $NF}' |xargs docker start
```

**或者**

```bash
在运行Docker容器时可以加如下参数来保证每次Docker服务重启后容器也自动重启：
--restart=always

–restart具体参数值详细信息：
	no：容器退出时，不重启容器；
	on-failure：只有在非0状态退出时才重新启动容器；	
	always：无论退出状态是如何，都重启容器；
```

#### 设置已启动的容器自启动

```bash
docker update --restart=always <docker容器CONTAINER ID 或 docekr容器NAMES>
# 反之： docker update --restart=no (docker容器CONTAINER ID 或 docekr容器NAMES)
```
