Home » DevOps » Docker » How to get the Docker container IP address

About Yatin

Yatin
The author is graduated in Electronics & Telecommunication. During his studies, he has been involved with a significant number of projects ranging from programming and software engineering to telecommunications analysis. He works as a technical lead in the information technology sector where he is primarily involved with projects based on Java/J2EE technologies platform and novel UI technologies.

How to get the Docker container IP address

Welcome readers, in this tutorial, we will discuss how to get an IP address assigned to a running docker container.

1. Introduction to Docker

In the present world, Docker is an important term,

  • Often used in CI/CD platform that packages and runs the application with its dependencies inside a container
  • Is a standard for Linux Containers
  • A Container is a runtime that runs under any Linux kernel and provides a private machine-like space under Linux

1.1 Docker Terminology

  • Image: Representation of Docker container i.e. a JAR or WAR file in Java
  • Container: Runtime of Docker i.e. a deployed and running Docker image. For example, an executable Spring Boot jar
  • Engine: The code that manages, creates and runs the Docker containers
  • Hub: A public developers registry to distribute their code
  • Repository: A collection of Docker related images i.e. different versions of the same application

1.2 Docker Command Basics

Here’s an example command.

Docker container IP - Basic structure
Fig. 1: Basic structure

1.3 Need for using Docker

  • For environment replication, while the code runs locally on the machine
  • For numerous deployment phases i.e. Dev/Test/QA
  • For version control and distributing the application’s OS within a team

1.4 Setting up Docker

If someone needs to go through the Docker installation, please watch this video.

To start with this tutorial, we are hoping that users at present have the Docker installed on a Windows operating system.

2. How to get the Docker Container IP address

The docker inspect command is used to get the low-level information such as Network settings, Config, Image, Mounts, etc. about the Docker Container in a JSON format. Below is the command syntax –

docker inspect <Option> <container_name | container_id>

To get the information about the Docker Container we need to make sure that the Docker Container(s) is up and running. To list this information, we can use the docker ps command as shown in Fig. 2.

Docker container IP - information of running Docker
Fig. 2: Viewing the information of running Docker Container(s)

2.1 Get Docker Container IP Address

To fetch the IP address for all the running containers we can use the following command –

docker ps -aq | xargs docker inspect -f '{{.Name}} - {{.NetworkSettings.IPAddress }}'

This command lists down the IP address of all the running docker containers as shown in Fig. 3.

Fig. 3: IP address

Try out these commands in your development environment to practice and learn.

3. Conclusion

That is all for this tutorial and I hope the tutorial will help you understand the basic commands to get the IP address for a Docker container. Happy Learning and do not forget to share!

4. Download the source code

Download
You can download the full source code of this example here: How to get the Docker container IP address
0 0 vote
Article Rating

Do you want to know how to develop your skillset to become a Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you our best selling eBooks for FREE!

 

1. JPA Mini Book

2. JVM Troubleshooting Guide

3. JUnit Tutorial for Unit Testing

4. Java Annotations Tutorial

5. Java Interview Questions

6. Spring Interview Questions

7. Android UI Design

 

and many more ....

 

Receive Java & Developer job alerts in your Area

 

Subscribe
Notify of
guest
The comment form collects your name, email and content to allow us keep track of the comments placed on the website. Please read and accept our website Terms and Privacy Policy to post a comment.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x