容器(二)

启动已经停止运行的容器

docker start 容器id/容器名

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[root@iZ8vbfaek3x3ogtpxnpnwfZ ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
562278524cda ubuntu "bash" 4 minutes ago Up 4 minutes loving_dewdney
9a1a43aee837 ubuntu "bush" 4 minutes ago Created admiring_wiles
cdee90a8c77d ubuntu "bash" 29 minutes ago Exited (0) 29 minutes ago ubuntu
0dcaa91afc0e ubuntu "/bin/bush" 31 minutes ago Created myubuntu
[root@iZ8vbfaek3x3ogtpxnpnwfZ ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
562278524cda ubuntu "bash" 4 minutes ago Up 4 minutes loving_dewdney
[root@iZ8vbfaek3x3ogtpxnpnwfZ ~]# docker start cdee90a8c77d
cdee90a8c77d
[root@iZ8vbfaek3x3ogtpxnpnwfZ ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
562278524cda ubuntu "bash" 5 minutes ago Up 5 minutes loving_dewdney
cdee90a8c77d ubuntu "bash" 30 minutes ago Up 3 seconds ubuntu
[root@iZ8vbfaek3x3ogtpxnpnwfZ ~]#

重启容器

docker restart 容器id/容器名

停止容器

docker stop 容器id/容器名

强制停止容器

docker kill 容器id/容器名

删除已经停止的容器

docker rm 容器id

一次性删除多个容器

  • docker rm -f $(docker ps -a -q)
  • docker ps -a -q | xargs docker rm

注:xargs是linux系统的可变参数,把分隔符前面的结果传给xargs里面,然后执行分隔符后面的命令

1
2
3
4
5
6
7
8
9
10
11
[root@iZ8vbfaek3x3ogtpxnpnwfZ ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
562278524cda ubuntu "bash" 20 minutes ago Up 20 minutes loving_dewdney
cdee90a8c77d ubuntu "bash" 45 minutes ago Up 15 minutes ubuntu
[root@iZ8vbfaek3x3ogtpxnpnwfZ ~]# docker ps -a -q | xargs docker rm -f
562278524cda
cdee90a8c77d
[root@iZ8vbfaek3x3ogtpxnpnwfZ ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[root@iZ8vbfaek3x3ogtpxnpnwfZ ~]#