docker_practice/container/stop.md
2018-12-19 17:24:52 +08:00

21 lines
1.1 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

## 终止容器
可以使用 `docker container stop` 来终止一个运行中的容器
此外 Docker 容器中指定的应用终结时容器也自动终止
例如对于上一章节中只启动了一个终端的容器用户通过 `exit` 命令或 `Ctrl+d` 来退出终端时所创建的容器立刻终止
终止状态的容器可以用 `docker container ls -a` 命令看到例如
```bash
docker container ls -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ba267838cc1b ubuntu:18.04 "/bin/bash" 30 minutes ago Exited (0) About a minute ago trusting_newton
98e5efa7d997 training/webapp:latest "python app.py" About an hour ago Exited (0) 34 minutes ago backstabbing_pike
```
处于终止状态的容器可以通过 `docker container start` 命令来重新启动
此外`docker container restart` 命令会将一个运行态的容器终止然后再重新启动它