简体   繁体   English

如何通过ip查找docker容器?

[英]How to find docker container by ip?

I got an container ip but do not know which it is, which should be one of dozens containers.我得到了一个容器ip,但不知道是哪个,应该是几十个容器中的一个。 So, what the fastest way to find it out?那么,找到它的最快方法是什么?

Thanks all.谢谢大家。

try this:试试这个:

echo $(docker ps -a -q) | xargs docker inspect --format '{{ .NetworkSettings.IPAddress }}  {{.Id}}' | grep MY_IP

result:结果:

MY_IP  fe82613520e138039924f979899bc46a40312687361a98b9a670273a0340f48c

I see you have tagged your question with Kubernetes, so I am assuming you are using that.我看到你用 Kubernetes 标记了你的问题,所以我假设你正在使用它。

Here is how to get container(s) by IP address in k8s:以下是在 k8s 中通过 IP 地址获取容器的方法:

kubectl get pod -ojsonpath='{range .items[*]}{@.metadata.name}{" "}{@.status.podIP}{"\n"}' | grep 127.0.0.1 # <==== Your IP
docker inspect  --format={{.Id}}-{{.NetworkSettings.IPAddress}} $(docker ps -aq)|grep $IP

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM