显示所有容器列表(包括启动状态的和未启动状态的;等同于docker ps -a):docker container ls -a
[root@localhost ~]# docker container ls -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 10c99f08efc8 thehunt33r/docker-brimir "/bin/sh -c '/etc/in…" 2 minutes ago Exited (137) 4 seconds ago hardcore_hugle 5f6083a38441 nginx "nginx -g 'daemon of…" 4 minutes ago Up 4 minutes 0.0.0.0:80->80/tcp youthful_fer
不加参数(-a)为只显示启动状态的容器列表
创建Docker容器(等同于docker craete):docker container create nginx #此方式仅是创建容器而不启动容器
[root@localhost ~]# docker image ls REPOSITORY TAG IMAGE ID CREATED SIZE nginx latest 42b4762643dc 7 days ago 109MB thehunt33r/docker-brimir latest b7bf3e5cd2cf 2 years ago 1.19GB [root@localhost ~]# docker container ls -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES [root@localhost ~]# docker container create nginx 7fc9e61ed8d40f27989caa1265465170d21de99b4ab5ad080ce520a4059e3dce [root@localhost ~]# docker container ls -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 7fc9e61ed8d4 nginx "nginx -g 'daemon of…" 4 seconds ago Created gallant_antonelli
启动指定Docker容器(等同于docker start):docker container start 容器名/ID
[root@localhost ~]# docker container ls -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 7fc9e61ed8d4 nginx "nginx -g 'daemon of…" 2 minutes ago Created gallant_antonelli [root@localhost ~]# docker container start 7fc9e61ed8d4 7fc9e61ed8d4 [root@localhost ~]# docker container ls -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 7fc9e61ed8d4 nginx "nginx -g 'daemon of…" 5 minutes ago Up 3 seconds 80/tcp gallant_antonelli
停止指定Docker容器(等同于docker stop):docker container stop 容器名/ID
[root@localhost ~]# docker container ls -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 7fc9e61ed8d4 nginx "nginx -g 'daemon of…" 8 minutes ago Up 3 seconds 80/tcp gallant_antonelli [root@localhost ~]# docker container stop gallant_antonelli gallant_antonelli [root@localhost ~]# docker container ls -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 7fc9e61ed8d4 nginx "nginx -g 'daemon of…" 8 minutes ago Exited (0) 3 seconds ago gallant_antonelli
重启指定Docker容器(等同于docker restart):docker container restart 容器名/ID
[root@localhost ~]# docker container ls -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 7fc9e61ed8d4 nginx "nginx -g 'daemon of…" 8 minutes ago Exited (0) 3 seconds ago gallant_antonelli [root@localhost ~]# docker container restart 7fc9e61ed8d4 7fc9e61ed8d4 [root@localhost ~]# docker container ls -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 7fc9e61ed8d4 nginx "nginx -g 'daemon of…" 10 minutes ago Up 2 seconds 80/tcp gallant_antonelli
杀死指定Docker容器(等同于docker kill):docker container kill 容器名/ID #当容器处于异常状态不能正常停止或重启时可用此命令结束容器
[root@localhost ~]# docker container ls -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 7fc9e61ed8d4 nginx "nginx -g 'daemon of…" 13 minutes ago Up 3 minutes 80/tcp gallant_antonelli [root@localhost ~]# docker container kill 7fc9e61ed8d4 7fc9e61ed8d4 [root@localhost ~]# docker container ls -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 7fc9e61ed8d4 nginx "nginx -g 'daemon of…" 14 minutes ago Exited (137) 3 seconds ago gallant_antonelli
删除非启动状态的容器(等同于docker rm):docker container rm 容器名/ID
[root@localhost ~]# docker container ls -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 7fc9e61ed8d4 nginx "nginx -g 'daemon of…" 13 minutes ago Up 3 minutes 80/tcp gallant_antonelli [root@localhost ~]# docker container kill 7fc9e61ed8d4 7fc9e61ed8d4 [root@localhost ~]# [root@localhost ~]# [root@localhost ~]# docker container ls -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 7fc9e61ed8d4 nginx "nginx -g 'daemon of…" 14 minutes ago Exited (137) 3 seconds ago gallant_antonelli [root@localhost ~]# docker container rm 7fc9e61ed8d4 7fc9e61ed8d4 [root@localhost ~]# docker container ls -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
强制删除容器(包括启动状态的和未启动状态的):docker container rm -f 容器名/ID
[root@localhost ~]# docker container ls -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 951b0a99aa0f nginx "nginx -g 'daemon of…" 5 seconds ago Up 4 seconds 80/tcp gallant_volhard [root@localhost ~]# docker container rm -f 951b0a99aa0f 951b0a99aa0f [root@localhost ~]# docker container ls -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES