为什么 docker ps -a 的名称列总是不同的

Why does the name column of the docker ps -a always different

我只是在玩 docker!!

运行 ps 命令-a 选项

docker run -a
C:\Users\sarkan1>docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                      PORTS               NAMES
3d6db385321c        busybox:1.24        "sleep 1000"        26 seconds ago      Up 24 seconds                                   lucid_ramanujan
e6acd65398b2        hello-world         "/hello"            43 minutes ago      Exited (0) 43 minutes ago                       nifty_brattain
c5576137580d        hello-world         "/hello"            4 days ago          Exited (0) 4 days ago                           dreamy_aryabhata
2594fbf1fa82        hello-world         "/hello"            4 days ago          Exited (0) 4 days ago                           nostalgic_hopper
c0102bc64c45        hello-world         "/hello"            4 days ago          Exited (0) 4 days ago                           vibrant_khorana
c4af79ea96e9        hello-world         "/hello"            4 days ago          Exited (0) 4 days ago                           cranky_heyrovsky

问题:

  1. 为什么我得到的名称列中的值总是不同的?我 运行 我猜是同一个容器!!

  2. 什么是命令栏?你好(/hello)前的斜杠有什么意义吗?

除非您启动指定名称的容器 (docker run --name),否则 docker 会为您生成一个。
这比使用其 ID 引用所述容器更容易。

然后您可以使用其(生成的)名称创建 docker 命令。

在“How does Docker generate default container names?”查看更多内容。
(和源代码:moby/moby pkg/namesgenerator/names-generator.go

命令栏是容器执行的完整命令:此命令停止,容器停止。
该命令在 docker 图像中指定,并且是以下组合:

(参见“”)

基本上它们是随机生成的容器名称!!名称的左右部分是硬编码的,可以在

中找到

https://github.com/moby/moby/blob/master/pkg/namesgenerator/names-generator.go

如果在创建新的 docker 容器时未提供默认名称,

Docker 引擎会生成它。