1、列举本地所有容器
$ sudo docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6b643e4e7c2d ror-centos-20180524001 "/bin/bash" 16 minutes ago Exited (0) 45 seconds ago sleepy_mcclintock
f44cf0ebec18 centos "/bin/bash" 40 minutes ago Exited (0) 24 minutes ago nostalgic_darwin
30b57f142412 centos "/bin/bash" About an hour ago Exited (127) About an hour ago xenodochial_booth
379adebe4b02 centos "/bin/bash" About an hour ago Exited (127) About an hour ago sharp_easley
如果不带-a则只列举正在运行的容器
2、启动指定容器
$ sudo docker start 6b643e4e7c2d
6b643e4e7c2d
3、停止指定容器
$ sudo docker stop 6b643e4e7c2d
6b643e4e7c2d
4、介入一个已经运行的容器
$ sudo docker attach 6b643e4e7c2d
[root@6b643e4e7c2d /]#
或者
$ sudo docker exec -it 6b643e4e7c2d /bin/sh
sh-4.2#
这两个命令的区别在于,attach命令介入容器后,执行exit会退出docker进程,从而导致docker停止。
而exec介入的话,执行exit退出只是退出容器的sh,不会导致docker停止。
5、删除容器
$ sudo docker rm 6b643e4e7c2d
6b643e4e7c2d
$ sudo docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f44cf0ebec18 centos "/bin/bash" About an hour ago Exited (0) About an hour ago nostalgic_darwin
30b57f142412 centos "/bin/bash" About an hour ago Exited (127) About an hour ago xenodochial_booth
379adebe4b02 centos "/bin/bash" 2 hours ago Exited (127) About an hour ago sharp_easley