【发布时间】:2016-03-11 23:26:57
【问题描述】:
【问题讨论】:
【问题讨论】:
这些是为您正在运行的每个容器生成的随机名称。
你可以在pkg/namesgenerator/names-generator.go看到这些名字。
// Docker, starting from 0.7.x, generates names from notable scientists and hackers.
// Please, for any amazing man that you add to the list, consider adding an equally amazing woman to it, and vice versa.
right = [...]string{
// Muhammad ibn Jābir al-Ḥarrānī al-Battānī was a founding father of astronomy. https://en.wikipedia.org/wiki/Mu%E1%B8%A5ammad_ibn_J%C4%81bir_al-%E1%B8%A4arr%C4%81n%C4%AB_al-Batt%C4%81n%C4%AB
"albattani",
// Frances E. Allen, became the first female IBM Fellow in 1989. In 2006, she became the first female recipient of the ACM's Turing Award. https://en.wikipedia.org/wiki/Frances_E._Allen
"allen",
...
您可以通过添加 --name to your docker run commands 来获得固定名称。
2013 年 10 月,Michael Crosby (crosbymichael) 为 docker 0.6.5 在 commit 0d29244 中引入了这种做法:
为
docker run添加-name删除泊坞窗链接
不要将容器 ID 添加为默认名称
如果在运行时未指定,则创建一个自动生成的容器名称。
Solomon Hykes (shykes) 在 docker 0.7 中使用commit 5d6ef317 改进了这种做法:
0.7 的新随机名称集合:
心情+著名发明家。
例如。 'sad-tesla' 或 'naughty-turing'
【讨论】:
正如 VonC 已经写的那样,“这些是为您正在运行的每个容器生成的随机名称”。那么为什么要使用自定义名称呢?
docker run [image-name] -[container-name]
docker run wildfly-8.1 -mywildfly
如果你想停止/杀死/运行/检查或对你的容器做任何事情,你可以使用你的名字这样做:
码头工人杀死我的码头工人
docker 运行 mydocker
否则,您必须一直执行 docker ps 并检查 id(因为您不会记住那些虚构的自定义名称)。
一个重要的旁注,如果您为 docker 分配自定义名称,它将永远分配给该特定容器,这意味着即使您杀死该容器,它也不再运行,您无法重用名字。 如果你跑
docker ps -a
您可以看到旧的仍然存在,但停止了。在 docker rm 删除前一个容器之前,您不能重复使用容器名称。
要删除超过某个自定义时间的容器,请使用以下命令:
$ docker ps -a | grep '几周前' | awk '{打印 $1}' | xargs --no-run-if-empty docker rm
更多关于删除容器here。
【讨论】: