Docker-compose命令-rm

命令

docker-compose rm

描述

Remove stopped containers
移除停止的容器

用法

1
rm [options] [SERVICE...]

选项

1
2
3
4
Options:
-f, --force Don't ask to confirm removal
-s, --stop Stop the containers, if required, before removing
-v Remove any anonymous volumes attached to containers

注意

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
$ docker-compose ps -a
Name Command State Ports
-----------------------------------------------------------------------------------------
demo_demo_run_368b1fe0df5f /docker-entrypoint.sh whoami Exit 0
demo_demo_run_9c4367d358bd /docker-entrypoint.sh ls / ... Exit 0
nginx1 /docker-entrypoint.sh ngin ... Up 0.0.0.0:80->80/tcp
$ docker-compose rm
Going to remove demo_demo_run_368b1fe0df5f, demo_demo_run_9c4367d358bd
Are you sure? [yN] y
Removing demo_demo_run_368b1fe0df5f ... done
Removing demo_demo_run_9c4367d358bd ... done
$ docker-compose ps -a
Name Command State Ports
--------------------------------------------------------------------
nginx1 /docker-entrypoint.sh ngin ... Up 0.0.0.0:80->80/tcp

$ docker-compose rm -f
No stopped containers
$ docker-compose rm -s
Stopping nginx1 ... done
Going to remove nginx1
Are you sure? [yN]
# -sf 强制删除所有服务容器,包括正在运行的服务
$ docker-compose rm -sf
Going to remove nginx1
Removing nginx1 ... done
$ docker-compose ps -a
Name Command State Ports
------------------------------