使用 Docker 部署时的容器名称
Container NAMES when deploying with Docker
我刚刚完成了我的第一次 Docker 部署,当我 运行 此命令查看最近进程的状态时...
docker ps -a
我得到了这个输出
我的问题是;这些名字指的是什么?
这些是为您所在的每个容器生成的随机名称 运行。
您可以在 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 月 commit 0d29244 by Michael Crosby (crosbymichael
) 为 docker 0.6.5 引入了这种做法:
Add -name
for docker run
Remove docker link
Do not add container id as default name
Create an auto generated container name if not specified at runtime.
Solomon Hykes (shykes
) evolved that practice in docker 0.7 with commit 5d6ef317:
New collection of random names for 0.7:
mood + famous inventor.
Eg. 'sad-tesla' or 'naughty-turing'
正如 VonC 所写,“这些是为您 运行ning 中的每个容器生成的随机名称”。那么为什么要使用自定义名称?
docker run [image-name] -[container-name]
docker run wildfly-8.1 -mywildfly
好吧,如果您想 stop/kill/run/inspect 或对您的容器做任何事情,您可以使用您的名字:
docker kill mydocker
docker run mydocker
否则你必须一直做dockerps并检查id(因为你不会记住那些虚构的自定义名称) .
一个重要的旁注,如果您将自定义名称分配给docker,它将永远分配给该特定容器,这意味着即使您杀死了容器,它不再是 运行ning,您不能重复使用该名称。
如果你运行
docker ps -a
你可以看到旧的还在,但是停了。在 docker rm.
删除之前的容器之前,您不能重新使用容器名称
要删除早于某个自定义时间的容器,请使用命令:
$ docker ps -a | grep 'weeks ago' | awk '{print }' | xargs
--no-run-if-empty docker rm
有关删除容器的更多信息 here。
我刚刚完成了我的第一次 Docker 部署,当我 运行 此命令查看最近进程的状态时...
docker ps -a
我得到了这个输出
我的问题是;这些名字指的是什么?
这些是为您所在的每个容器生成的随机名称 运行。
您可以在 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 月 commit 0d29244 by Michael Crosby (crosbymichael
) 为 docker 0.6.5 引入了这种做法:
Add
-name
fordocker run
Remove docker link
Do not add container id as default name
Create an auto generated container name if not specified at runtime.
Solomon Hykes (shykes
) evolved that practice in docker 0.7 with commit 5d6ef317:
New collection of random names for 0.7:
mood + famous inventor.
Eg. 'sad-tesla' or 'naughty-turing'
正如 VonC 所写,“这些是为您 运行ning 中的每个容器生成的随机名称”。那么为什么要使用自定义名称?
docker run [image-name] -[container-name]
docker run wildfly-8.1 -mywildfly
好吧,如果您想 stop/kill/run/inspect 或对您的容器做任何事情,您可以使用您的名字:
docker kill mydocker
docker run mydocker
否则你必须一直做dockerps并检查id(因为你不会记住那些虚构的自定义名称) .
一个重要的旁注,如果您将自定义名称分配给docker,它将永远分配给该特定容器,这意味着即使您杀死了容器,它不再是 运行ning,您不能重复使用该名称。 如果你运行
docker ps -a
你可以看到旧的还在,但是停了。在 docker rm.
删除之前的容器之前,您不能重新使用容器名称要删除早于某个自定义时间的容器,请使用命令:
$ docker ps -a | grep 'weeks ago' | awk '{print }' | xargs --no-run-if-empty docker rm
有关删除容器的更多信息 here。