Simon
Simon

Reputation: 41

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.

Upvotes: 3

Views: 1749

Answers (3)

whirlwin
whirlwin

Reputation: 16521

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

Upvotes: 2

shubham_asati
shubham_asati

Reputation: 687

docker inspect  --format={{.Id}}-{{.NetworkSettings.IPAddress}} $(docker ps -aq)|grep $IP

Upvotes: 1

LinPy
LinPy

Reputation: 18578

try this :

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

result :

MY_IP  fe82613520e138039924f979899bc46a40312687361a98b9a670273a0340f48c

Upvotes: 4

Related Questions