Find Ip of Docker Container-Find ip of All the Running Docker Containers

in this tutorial i will show you how to find Ip address of Docker Container and Find ip of All the Running Docker Containers.

find ip of all the running docker containers

docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $(docker ps -q)

this command will show you all ip addresses of running docker containers. in my host machine i have 2 containers running and 1 is stopped. so it will show you the only running container ip addresses

docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $(docker ps -q)
172.17.0.2
172.17.0.3

find ip of docker container

docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}'   container id or name

to find ip adress of any container use this command

[root@ip-10-0-0-22 ~]# docker ps
CONTAINER ID        IMAGE                 COMMAND                  CREATED             STATUS              PORTS                                              NAMES
59de9b7f3913        mysql                 "docker-entrypoint.s…"   3 minutes ago       Up 3 minutes        3306/tcp, 33060/tcp                                some-mysql
71b066c63371        jenkins/jenkins:lts   "/sbin/tini -- /usr/…"   6 minutes ago       Up 6 minutes        0.0.0.0:8080->8080/tcp, 0.0.0.0:50000->50000/tcp   eloquent_bhaskara

Here i am having two containers. The containers names and container id respectively  are some-mysql,59de9b7f3913 and second one is eloquent_bhaskara,71b066c63371

[root@ip-10-0-0-22 ~]# docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' some-mysql
172.17.0.3
[root@ip-10-0-0-22 ~]# docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' 59de9b7f3913
172.17.0.3

find ip of docker container using shell commands

docker inspect container_id | grep -i "ip.*[12]*\.[0-9]*" | sed -e 's/^ *//g' -e 's/[",]//g' -e 's/[a-zA-Z: ]//g'|grep 172|sort --unique;

[root@ip-10-0-0-22 ~]# docker inspect 59de9b7f3913 | grep -i "ip.*[12]*\.[0-9]*" | sed -e 's/^  *//g' -e 's/[",]//g' -e 's/[a-zA-Z: ]//g'|grep 172|sort --unique;
172.17.0.3

find ip docker container from container host file

docker exec -it  container_id  cat /etc/hosts

or

docker exec -it  container_name  cat /etc/hosts

[root@ip-10-0-0-22 ~]# docker exec -it 59de9b7f3913 cat /etc/hosts
127.0.0.1       localhost
::1     localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
172.17.0.3      20321315966b

here you can see ip address of docker container i,e 172.17.0.3

 

  • find ip of running docker container
  • find ip address of running docker container

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *