How to find docker container by ip?

11/29/2019

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.

-- Simon
docker
docker-compose
kubernetes

3 Answers

11/29/2019
docker inspect  --format={{.Id}}-{{.NetworkSettings.IPAddress}} $(docker ps -aq)|grep $IP
-- shubham_asati
Source: StackOverflow

11/29/2019

try this :

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

result :

MY_IP  fe82613520e138039924f979899bc46a40312687361a98b9a670273a0340f48c
-- LinPy
Source: StackOverflow

11/29/2019

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
-- whirlwin
Source: StackOverflow