从容器名称获取Docker容器ID [英] Get docker container id from container name
本文介绍了从容器名称获取Docker容器ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
从容器名称获取docker容器ID的命令是什么?
What is the command to get the docker container id from the container name?
推荐答案
在Linux中:
sudo docker ps -aqf "name=containername"
或在OS X,Windows中:
Or in OS X, Windows:
docker ps -aqf "name=containername"
其中 containername
是您的容器名称。
为避免误报,如@llia Sidorenko所述,您可以像这样使用正则表达式锚点:
To avoid getting false positives, as @llia Sidorenko notes, you can use regex anchors like so:
docker ps -aqf "name=^containername$"
说明:
-
-q
以保持安静。全部输出ID -
-a
。即使您的容器没有运行也可以使用 -
-f
对于过滤器。 -
^
容器名称必须使用此字符串开始 -
$
容器名称必须 end 使用此字符串
-q
for quiet. output only the ID-a
for all. works even if your container is not running-f
for filter.^
container name must start with this string$
container name must end with this string
这篇关于从容器名称获取Docker容器ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文