Docker系列(四):Docker容器管理

上面已经介绍了Docker镜像管理的常用命令,有了镜像之后就可以方便的运行容器了,所以本篇就依据容器的生命周期来展开,主要记录Docker容器管理的常用命令和示例。


创建容器:

docker create [OPTIONS] IMAGE [COMMAND] [ARG...]

创建并运行容器:

docker run [OPTIONS] IMAGE [COMMAND] [ARG...]

PS:因为以上两个命令都是用来创建容器,且命令的参数相似,而docker create用的不多,一般以docker run为主进行介绍。

启动参数:

-i, --interactive:交互式

-t, --tty:分配一个伪终端

-d, --detach: 运行容器到后台

-a, --attach list:附加到运行的容器

--dns list:设置DNS服务器

-e, --env list:设置环境变量

--env-file list:从文件读取环境变量

-p, --publish list:发布容器端口到主机

-P, --publish-all:发布容器所有EXPOSE的端口到宿主机随机端口

-h, --hostname string:设置容器主机名

--ip string:设定容器IP,只能用于自定义网络

--link list:添加连接到另一个容器

--network:连接容器到一个网络

--mount mount:挂载宿主机分区到容器

-v, --volume list:挂载宿主机目录到容器

--restart string:容器退出时重启策略,默认no [always|on-failure]

--add-host list:添加其他主机到容器中/etc/hosts

资源限制参数:

-m, --memory:容器可以使用的最大内存量

--memory-swap:允许交换到磁盘的内存量

--memory-swapiness=<0-100>:容器使用swap分区交换的百分比(0-100,默认为-1)

--memory-reservation:内存软限制,Docker检测主机容器争用或内存不足时所激活的软限制,使用此选项,值必须设置低于-memory,以使其优先

--oom-kill-disable:当宿主机内存不足时,内核会杀死容器中的进程。建议设置了-memory选项再禁用OOM。如果没有设置,主机可能会耗尽内存

--cpus:限制容器可以使用多少可用的CPU资源

--cpuset-cpus:限制容器可以使用特定的CPU

--cpu-shares:此值设置为大于或小于默认1024值,以增加或减少容器的权重,并使其可以访问主机CPU周期的更大或更小比例

示例:

创建一个容器

[root@centos7 ~]# docker create -it --name centos01 centos:latest
7aa2a5ddae29ee41f2ef774504d0f547cd26aeaa33bbed0cd167eaa8960d9778
[root@centos7 ~]# docker run -it --name centos02 centos:latest
[root@073dcceedc07 /]#

创建一个名为busybox01的容器,且后台运行

[root@centos7 ~]# docker run -itd --name busybox01 busybox
e41ee0ce0c03995e7dff56f0d6e6ae370a105d704681f373649e231b9e59e861
# 注意:因为docker create仅创建容器,并不启动容器,所以docker create并没有-d参数。

创建一个名为centos03的容器,设置其DNS地址为114.114.114.114,容器的主机名为centos03,并添加一个环境变量token,其值为hello。

[root@centos7 ~]# docker run -itd --name centos03 --dns 114.114.114.114 -e "token=hello" -h centos03 centos
6008f2b49accfc60a7d6b663cce393768255915181d0c21d3408a4e09edce720
[root@centos7 ~]# docker exec -it centos03 /bin/bash
[root@centos03 /]# hostname
centos03
[root@centos03 /]# cat /etc/resolv.conf 
search contoso.com
nameserver 114.114.114.114
[root@centos03 /]# echo $token
hello

创建一个名为websrv01的容器,将容器的tcp 80端口映射到本地主机的tcp 8080端口,另外将本地的/usr/share/nginx/html目录只读挂载到容器的/usr/share/nginx/html目录

[root@centos7 ~]# mkdir /usr/share/nginx/html -p
[root@centos7 ~]# echo "hello,world." >> /usr/share/nginx/html/index.html
[root@centos7 ~]# docker run -itd --name websrv01 -p 8080:80/tcp -v /usr/share/nginx/html:/usr/share/nginx/html:ro nginx 
05701d7807761f5569cd4ce37ff465135c2ebbf727924852f3ed4f203aff2922
[root@centos7 ~]# curl http://127.0.0.1:8080
hello,world.

创建一个名为centos04的容器,限制其最多只能使用1个cpu

[root@centos7 ~]# docker run -itd --name centos04 --cpus 1 centos
99f8cbf1bba1db7045be7bbcc4b51124dea8690c4b1f2d220fdc46fbddebd762
[root@centos7 ~]# docker stats centos04
CONTAINER           CPU %               MEM USAGE / LIMIT     MEM %               NET I/O             BLOCK I/O           PIDS
centos04            0.00%               376 KiB / 3.686 GiB   0.01%               648 B / 648 B       0 B / 0 B           1

创建一个名为centos05的容器,限制其最多只能使用2个cpu,且绑定到本地主机的前两个cpu核心

[root@centos7 ~]# docker run -itd --name centos05 --cpuset-cpus=0,1 --cpus=2 centos
d2439dfe16a886716bc8b610141f7a0a6376bfe51fc00e656b9a4bcda0b6aa2b

创建一个名为centos06的容器,限制其最大内存为512M

[root@centos7 ~]# docker run -itd --name centos06 --memory 512m centos
597bcf3f998f9d7eb8359e90e201233045698feebd29a40bb8ca694638a6012e
[root@centos7 ~]# docker stats centos06
CONTAINER           CPU %               MEM USAGE / LIMIT   MEM %               NET I/O             BLOCK I/O           PIDS
centos06            0.00%               380 KiB / 512 MiB   0.07%               648 B / 648 B       0 B / 0 B           1


查看容器:

docker ps [OPTIONS]

    -a, --all:查看所有容器(包括已经停止的)

    -f, --filter filter:根据提供的条件输出要显示的容器

    -n, --last int:查看最后(近)n个创建的容器

    -l, --latest:查看最后一个创建的容器(包括所有状态下的容器)

    -q, --quite:仅显示容器ID

    -s, --size:显示容器的总文件大小

该命令会返回一个列表,其中各列的含义如下:

     CONTAINER ID:容器的唯一表示ID。

     IMAGE:创建容器时使用的镜像。

     COMMAND:容器最后运行的命令。

     CREATED:创建容器的时间。

     STATUS:容器状态。

     PORTS:对外开放的端口。

     NAMES:容器名。可以和容器ID一样唯一标识容器,同一台宿主机上不允许有同名容器存在,否则会冲突。

示例:

[root@centos7 ~]# docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
597bcf3f998f        centos              "/bin/bash"         14 minutes ago      Up 14 minutes                           centos06
d2439dfe16a8        centos              "/bin/bash"         18 minutes ago      Up 18 minutes                           centos05
[root@centos7 ~]# docker ps -l
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
597bcf3f998f        centos              "/bin/bash"         14 minutes ago      Up 14 minutes                           centos06
[root@centos7 ~]# docker ps -n 1
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
597bcf3f998f        centos              "/bin/bash"         14 minutes ago      Up 14 minutes                           centos06
[root@centos7 ~]# docker ps -f name=centos*
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
597bcf3f998f        centos              "/bin/bash"         14 minutes ago      Up 14 minutes                           centos06
d2439dfe16a8        centos              "/bin/bash"         19 minutes ago      Up 19 minutes                           centos05
[root@centos7 ~]# docker ps -f status=running
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
597bcf3f998f        centos              "/bin/bash"         17 minutes ago      Up 17 minutes                           centos06
d2439dfe16a8        centos              "/bin/bash"         22 minutes ago      Up 22 minutes                           centos05
[root@centos7 ~]# docker ps -f status=created
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
54fa9de76500        busybox             "sh"                25 seconds ago      Created                                 busybox01
[root@centos7 ~]# docker ps -q
597bcf3f998f
d2439dfe16a8
[root@centos7 ~]# docker ps -s
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES               SIZE
597bcf3f998f        centos              "/bin/bash"         15 minutes ago      Up 15 minutes                           centos06            0 B (virtual 202 MB)
d2439dfe16a8        centos              "/bin/bash"         19 minutes ago      Up 19 minutes                           centos05            0 B (virtual 202 MB)


修改容器:

docker update [OPTIONS] CONTAINER [CONTAINER...]    更新一个或多个容器的配置

该命令支持修改容器的cpu、内存等相关配置,所用到的参数跟启动容器时使用到的参数大体一致,在此就不一一列举了。

示例:

[root@centos7 ~]# docker run -itd --name centos07 --cpuset-cpus 0 --memory 512m centos
c410b13fb5d7a4140facfecb30a1d17c470c54e343506a1dffa153d3caef9218
[root@centos7 ~]# docker update --cpuset-cpus 1 --memory 1024m centos07
centos07
[root@centos7 ~]# docker stats centos07
CONTAINER           CPU %               MEM USAGE / LIMIT   MEM %               NET I/O             BLOCK I/O           PIDS
centos07            0.00%               380 KiB / 1 GiB     0.04%               648 B / 648 B       0 B / 0 B           1


停止容器:

docker stop [OPTIONS] CONTAINER [CONTAINER...]

    -t, --time int:在彻底杀掉容器前等待指定秒数

示例:

[root@centos7 ~]# docker stop centos05
centos05
[root@centos7 ~]# docker stop -t 2 centos06
centos06


删除容器:

docker rm [OPTIONS] CONTAINER [CONTAINER...]

    -f, --force:强制关闭一个正在运行的容器

    -l, --link:移除指定链接

    -v, --volumes:移除绑定到容器上的卷

示例:

[root@centos7 ~]# docker ps -f name=centos*
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
597bcf3f998f        centos              "/bin/bash"         38 minutes ago      Up 21 seconds                           centos06
d2439dfe16a8        centos              "/bin/bash"         42 minutes ago      Up 23 seconds                           centos05
[root@centos7 ~]# docker rm centos06
Error response from daemon: You cannot remove a running container 597bcf3f998f9d7eb8359e90e201233045698feebd29a40bb8ca694638a6012e. Stop the container before attempting removal or use -f
[root@centos7 ~]# docker stop centos06
centos06
[root@centos7 ~]# docker rm centos06
centos06
[root@centos7 ~]# docker rm -f centos05
centos05
[root@centos7 ~]# docker rm -v websrv01
Error response from daemon: You cannot remove a running container b1136055649aec6ac010e6fd2dea0038e7dc4b94c69b352eb43f971539152904. Stop the container before attempting removal or use -f
[root@centos7 ~]# docker rm -fv websrv01
websrv01


附加容器:

docker attach [OPTIONS] CONTAINER   附加到一个正在运行的容器中

[root@centos7 ~]# docker run -itd --name centos03 centos
20c77fd15674dc21b43b2129b47e99367e3780b8156da65d84389880bb468d26
[root@centos7 ~]# docker attach centos03
[root@20c77fd15674 /]# ps -ef
UID         PID   PPID  C STIME TTY          TIME CMD
root          1      0  0 10:18 ?        00:00:00 /bin/bash
root         13      1  0 10:18 ?        00:00:00 ps -ef
[root@20c77fd15674 /]# exit
exit
[root@centos7 ~]# docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                     PORTS               NAMES
20c77fd15674        centos              "/bin/bash"         18 seconds ago      Exited (0) 2 seconds ago                       centos03

注意:如果使用docker attach进入到容器的交互模式,使用exit会使容器退出,此时可以使用CTRL+P、CRTL+Q组合键退出容器交互界面,这样就避免了容器退出的问题。


容器执行命令:

docker exec [OPTIONS] CONTAINER COMMAND [ARG...]     在一个运行中的容器中执行命令

  -d, --detach              分离模式,在后台执行命令

  -e, --env list              设置环境变量,默认为[]

  -i, --interactive          保持标准输出打开,及时没有附加到容器

      --privileged           执行需要其他权限的命令

  -t, --tty                      分配一个pty

  -u, --user string         指定用户名或者UID,格式为 : <name|uid>[:<group|gid>]

示例:

[root@centos7 ~]# docker run -itd --name centos01 centos
5bf713f499af4a4bb78308fa51f6650170e774f55bd0072c40482f218f71bd02
[root@centos7 ~]# docker exec -d centos01 ping www.baidu.com
[root@centos7 ~]# docker top centos01
UID                 PID                 PPID                C                   STIME               TTY                 TIME                CMD
root                1633                1618                0                   09:19               pts/1               00:00:00            /bin/bash
root                1690                1675                0                   09:21               ?                   00:00:00            ping www.baidu.com
[root@centos7 ~]# docker exec -it centos01 /bin/bash
[root@5bf713f499af /]# ps 
   PID TTY          TIME CMD
    17 ?        00:00:00 bash
    29 ?        00:00:00 ps

注:使用docker exec进入容器交互模式后,可以使用exit退出,这不会造成容器退出,这点有别于docker attach。

[root@centos7 ~]# docker exec -it -e var=abc centos01 bash
[root@5bf713f499af /]# echo $var
abc


查看容器日志:

docker logs [OPTIONS] CONTAINER

      --details           显示额外的详细信息到日志中(有则显示)

  -f, --follow           监视日志输出(相当于tail -f的输出)

      --since string   显示自某一时间戳后的日志Show logs since timestamp

      --tail string      显示自日志结尾的N行(相当于tail -n的输出)

  -t, --timestamps  显示时间戳

示例:

[root@centos7 ~]# docker run -itd --name websrv01 -p 8080:80 -v /usr/share/nginx/html:/usr/share/nginx/html:ro nginx
c39e285d431b3718d50e51946f4ad97f1fa1ae833ca66e774a880414c3a94b43
[root@centos7 ~]# docker logs websrv01
172.17.0.1 - - [14/Feb/2019:01:41:16 +0000] "GET / HTTP/1.1" 200 13 "-" "curl/7.29.0" "-"
172.17.0.1 - - [14/Feb/2019:01:41:17 +0000] "GET / HTTP/1.1" 200 13 "-" "curl/7.29.0" "-"
172.17.0.1 - - [14/Feb/2019:01:41:17 +0000] "GET / HTTP/1.1" 200 13 "-" "curl/7.29.0" "-"
172.17.0.1 - - [14/Feb/2019:01:41:18 +0000] "GET / HTTP/1.1" 200 13 "-" "curl/7.29.0" "-"
注:此时在另外一个session中执行如下命令:
[root@centos7 ~]# for i in `seq 20`;do curl http://localhost:8080/;sleep 2;done
[root@centos7 ~]# docker logs -f websrv01
172.17.0.1 - - [14/Feb/2019:01:41:16 +0000] "GET / HTTP/1.1" 200 13 "-" "curl/7.29.0" "-"
172.17.0.1 - - [14/Feb/2019:01:41:17 +0000] "GET / HTTP/1.1" 200 13 "-" "curl/7.29.0" "-"
172.17.0.1 - - [14/Feb/2019:01:41:17 +0000] "GET / HTTP/1.1" 200 13 "-" "curl/7.29.0" "-"

注:使用-f进入监视模式,用作持续观察日志输出,退出时使用CTRL+C键。

[root@centos7 ~]# docker logs -t --details websrv01
2019-02-14T01:41:16.434219000Z  172.17.0.1 - - [14/Feb/2019:01:41:16 +0000] "GET / HTTP/1.1" 200 13 "-" "curl/7.29.0" "-"
2019-02-14T01:41:17.369332000Z  172.17.0.1 - - [14/Feb/2019:01:41:17 +0000] "GET / HTTP/1.1" 200 13 "-" "curl/7.29.0" "-"
2019-02-14T01:41:17.851037000Z  172.17.0.1 - - [14/Feb/2019:01:41:17 +0000] "GET / HTTP/1.1" 200 13 "-" "curl/7.29.0" "-"
[root@centos7 ~]# docker logs -t --tail 5 websrv01
2019-02-14T01:42:15.467576000Z 172.17.0.1 - - [14/Feb/2019:01:42:15 +0000] "GET / HTTP/1.1" 200 13 "-" "curl/7.29.0" "-"
2019-02-14T01:42:17.478720000Z 172.17.0.1 - - [14/Feb/2019:01:42:17 +0000] "GET / HTTP/1.1" 200 13 "-" "curl/7.29.0" "-"
2019-02-14T01:42:19.491140000Z 172.17.0.1 - - [14/Feb/2019:01:42:19 +0000] "GET / HTTP/1.1" 200 13 "-" "curl/7.29.0" "-"
2019-02-14T01:42:21.502774000Z 172.17.0.1 - - [14/Feb/2019:01:42:21 +0000] "GET / HTTP/1.1" 200 13 "-" "curl/7.29.0" "-"
2019-02-14T01:42:23.513828000Z 172.17.0.1 - - [14/Feb/2019:01:42:23 +0000] "GET / HTTP/1.1" 200 13 "-" "curl/7.29.0" "-"


暂停容器:

docker pause CONTAINER [CONTAINER...]   暂停一个或多个容器的所有进程

示例:

[root@centos7 ~]# docker pause websrv01
websrv01
[root@centos7 ~]# docker ps -l
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                   PORTS                  NAMES
c39e285d431b        nginx               "nginx -g 'daemon ..."   31 minutes ago      Up 31 minutes (Paused)   0.0.0.0:8080->80/tcp   websrv01
[root@centos7 ~]# curl --connect-timeout 15 -m 30 http://localhost:8080
curl: (28) Operation timed out after 30000 milliseconds with 0 out of -1 bytes received


恢复容器:

docker unpause CONTAINER [CONTAINER...]    恢复一个或多个容器的所有进程

示例:

[root@centos7 ~]# docker unpause websrv01
websrv01
[root@centos7 ~]# docker ps -l
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                  NAMES
c39e285d431b        nginx               "nginx -g 'daemon ..."   38 minutes ago      Up 38 minutes       0.0.0.0:8080->80/tcp   websrv01
[root@centos7 ~]# curl --connect-timeout 15 -m 30 http://localhost:8080
hello,world.


查看容器端口映射:

docker port CONTAINER [PRIVATE_PORT[/PROTO]]

示例:

[root@centos7 ~]# docker port websrv01
80/tcp -> 0.0.0.0:8080


重命名容器:

docker rename CONTAINER NEW_NAME

示例:

[root@centos7 ~]# docker ps -l
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                  NAMES
c39e285d431b        nginx               "nginx -g 'daemon ..."   44 minutes ago      Up 44 minutes       0.0.0.0:8080->80/tcp   websrv01
[root@centos7 ~]# docker rename websrv01 nginx01
[root@centos7 ~]# docker ps -l
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                  NAMES
c39e285d431b        nginx               "nginx -g 'daemon ..."   45 minutes ago      Up 45 minutes       0.0.0.0:8080->80/tcp   nginx01


显示容器资源使用情况:

docker stats [OPTIONS] [CONTAINER...]

      -a, --all               显示所有容器的资源使用情况(默认仅显示正在运行的容器的资源使用情况)

      --format string   格式化输出(使用Go模板展示)

示例:

[root@centos7 ~]# docker stats --all
CONTAINER           CPU %               MEM USAGE / LIMIT       MEM %               NET I/O             BLOCK I/O           PIDS
c39e285d431b        0.00%               1.395 MiB / 3.686 GiB   0.04%               16.4 kB / 17.7 kB   15.8 MB / 0 B       2
5bf713f499af        --                  -- / --                 --                  --                  --                  --
20c77fd15674        --                  -- / --                 --                  --                  --                  --
54fa9de76500        --                  -- / --                 --                  --                  --                  --
......
[root@centos7 ~]# docker stats --all --format "table {{.Container}}\t{{.CPUPerc}}\t{{.MemUsage}}" nginx01 centos01 mycentos busybox01
CONTAINER           CPU %               MEM USAGE / LIMIT
nginx01             0.00%               1.395 MiB / 3.686 GiB
centos01            --                  -- / --
mycentos            --                  -- / --
busybox01           --                  -- / --
......


查看容器的详细信息:

docker inspect [OPTIONS] NAME|ID [NAME|ID...]

该命令既可以查看容器的信息也可以查看镜像的信息,官方的解释是:返回Docker对象的底层信息。相关参数在上一篇就已经介绍,不再赘述。


查看容器进程:

docker top CONTAINER [ps OPTIONS]      列出单个容器正在运行的进程列表

示例:

[root@centos7 ~]# docker top nginx01
UID                 PID                 PPID                C                   STIME               TTY                 TIME                CMD
root                1907                1893                0                   09:40               pts/1               00:00:00            nginx: master process nginx -g daemon off;
101                 1929                1907                0                   09:40               pts/1               00:00:00            nginx: worker process


杀掉容器:

docker kill [OPTIONS] CONTAINER [CONTAINER...]      杀掉一个或多个正在运行的容器

示例:

[root@centos7 ~]# docker ps -l
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
2a1c58409cc1        centos              "/bin/bash"         7 seconds ago       Up 6 seconds                            centos01
[root@centos7 ~]# docker kill centos01
centos01
[root@centos7 ~]# docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                       PORTS               NAMES
2a1c58409cc1        centos              "/bin/bash"         16 seconds ago      Exited (137) 2 seconds ago                       centos01


重启容器:

docker restart [OPTIONS] CONTAINER [CONTAINER...]     重启一个或多个容器

示例:

[root@centos7 ~]# docker restart centos01
centos01
[root@centos7 ~]# docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED              STATUS              PORTS               NAMES
2a1c58409cc1        centos              "/bin/bash"         About a minute ago   Up 5 seconds                            centos01


补充:

跟前篇一致,上面都是docker 1.12版本之前的命令,在docker 1.13版对于容器管理也添加了新的命令集,其顶级命令为docker container,包含如下命令:

  attach      附加到容器(相当于docker attach)

  commit    从一个修改的容器创建一个新的镜像(相当于docker commit)

  cp            在一个容器和本地文件系统中拷贝文件/目录

  create      创建一个新的容器

  diff           检查一个容器文件系统的修改

  exec         在一个运行的容器中执行命令

  export      将一个容器的文件系统导出为tar包

  inspect     显示一个或多个容器的详细信息

  kill            杀掉一个或多个运行中的容器

  logs          捕捉单个容器的日志输出

  ls              列举容器列表

  pause       暂停一个或多个容器中的所有进程

  port          列出容器中映射的端口

  prune       移除所有停止的容器

  rename    重命名一个容器

  restart      重启一个或多个容器

  rm            删除一个或多个容器

  run           在一个新容器中运行一条命令

  start         启动一个或多个已停止的容器

  stats         显示一个或多个容器的动态资源统计

  stop          停止一个或多个运行中的容器

  top           显示单个容器中运行的所有进程

  unpause   取消暂停一个或多个容器中的所有进程

  update      修改一个或多个容器的配置

  wait          锁定一个或多个容器,知道它们停止,然后打印它们的退出状态码

这其中,仅有1个命令是新增的,也就是docker container prune,因此仅对此进行说明,其他可以参照上面的命令。这里并非不推荐使用Docker 1.13的命令,而是很多命令大家都用了很久习惯了,相反很推荐使用Docker 1.13的命令,因为命令根据Docker对象进行了系统化,还是很有便捷性的。


移除所有停止的容器:

docker container prune [OPTIONS]  

    -f, --force   强制清除,不进行命令行确认

示例:

[root@centos7 ~]# docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                     PORTS               NAMES
b3a3c06f9a75        centos              "/bin/bash"         6 minutes ago       Exited (0) 6 minutes ago                       centos03
f49e5ffa0a72        busybox             "sh"                6 minutes ago       Exited (0) 6 minutes ago                       busybox01
2a1c58409cc1        centos              "/bin/bash"         36 minutes ago      Up 35 minutes                                  centos01
[root@centos7 ~]# docker container prune 
WARNING! This will remove all stopped containers.
Are you sure you want to continue? [y/N] n
Total reclaimed space: 0 B
[root@centos7 ~]# docker container prune -f
Deleted Containers:
b3a3c06f9a7568790753f1ed54e37160ae0077908559e870c305c3bfaf936405
f49e5ffa0a7248320867563b5a849f13219e38024b25bc435d01038a2569f631
Total reclaimed space: 23 B
[root@centos7 ~]# docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
2a1c58409cc1        centos              "/bin/bash"         37 minutes ago      Up 35 minutes                           centos01


猜你喜欢

转载自blog.51cto.com/jerry12356/2350075