How to Get a Docker Container’s Ip Address from the Host?

Better Stack Team
Updated on March 16, 2023

By default, the container is assigned an IP address for every Docker network it connects to. And each network is created with a default subnet mask, using it as a pool, later on, to give away the IP addresses.

How to get the IP address?

To get the IP address of a Docker container, you can use the inspect command, alongside the -format option as shown below:

On Linux

docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' container_name_or_id

On Windows

docker inspect -f "{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}" container_name_or_id

The command will return the Docker container’s IP address.

Got an article suggestion? Let us know
Explore more
Licensed under CC-BY-NC-SA

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

We are hiring.

Software is our way of making the world a tiny bit better. We build tools for the makers of tomorrow.

Explore all positions →