简体   繁体   中英

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. 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.

Here is how to get container(s) by IP address in k8s:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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