Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (2.3k points)

How can one get a container's IP address from the host ?

What I am trying to do is to deploy my own code and run configuration scripts for container.

closed

1 Answer

+1 vote
by (6.9k points)
selected by
 
Best answer

There is a simple command to get an IP of a container

 docker inspect < name_of_container >

If you want to use it in configuration scripts you can write the command like this 

ABC=$(docker run -d -p 4321 base nc -lk 4321);

docker inspect $ABC

There is a slight issue with though, when you run the inspect command - You will get a lot more things than just the IP address of the container.

To get just the IP address you can use grep :

docker inspect < name_of_container > | grep "IPAddress" 

This will give you the IP address of the container only. 


Also If you want to become more adept with docker you can check this Docker training course . You will be trained by industry professionals who have years of experience in docker. Or you can check out this Docker Tutorial to get to know more about how to use docker.

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...