Find a Docker container IP address
Inspect addresses by network, distinguish IPv4 and IPv6, and avoid confusing a container address with a published host endpoint.
Use docker inspect to read a container's network attachments. Print a network name beside each address so a container on several networks does not produce an ambiguous string of concatenated IPs.
docker inspect --format '{{range $name, $net := .NetworkSettings.Networks}}{{printf "%s\tIPv4=%s\tIPv6=%s\n" $name $net.IPAddress $net.GlobalIPv6Address}}{{end}}' myapp
For a concise view of one known network:
docker inspect --format '{{with index .NetworkSettings.Networks "myapp_default"}}{{.IPAddress}}{{end}}' myapp
Replace the network name with the actual one. A blank result can mean that network is absent or has no IPv4 address; it is not proof that every form of connectivity is broken.
Inspect the full network object
docker inspect --format '{{json .NetworkSettings.Networks}}' myapp | python3 -m json.tool
This requires Python on the CLI machine. The object shows each attachment and its relevant fields. Network drivers differ: host networking does not allocate an independent bridge address, and none provides no ordinary external network attachment.
In PowerShell, single quotes are useful for protecting Go-template variables such as $name from PowerShell expansion. For a simple address-only expression:
docker inspect --format '{{range .NetworkSettings.Networks}}{{println .IPAddress}}{{end}}' myapp
Check your shell's argument-passing behavior for more complex templates containing embedded quotes.
Use stable service names for applications
A dynamically allocated address can change when a container is replaced; it is not guaranteed to change every time. On a user-defined network, use the container or Compose service name where Docker DNS is available. A Compose application should normally connect to its database by service name and container port.
For host or external access, publish an appropriate port instead of assuming the private container address is routed to the client:
docker run -d --name web -p 127.0.0.1:8080:80 nginx:stable
docker port web
Here, the local host uses 127.0.0.1:8080. A remote client would need an intentionally reachable host binding and suitable access controls.
FAQ
Why is the address empty?
Check whether the container is stopped, uses host or none networking, lacks that named attachment, or uses a different address family. Inspect the full state before choosing a remedy.
Can the host ping a container IP?
Native Linux bridge setups often allow direct host-to-container traffic, but firewall and network configuration still matter. Docker Desktop Linux containers sit behind its VM networking, so direct host routing differs. A failed ICMP test also does not prove an application's TCP port is unavailable.
When is the raw IP useful?
For a short-lived routing, firewall, or connection diagnosis. Test the actual protocol and port, then prefer service discovery or a deliberately published endpoint in persistent configuration.
See Docker networking, inspect, and Desktop networking.
Contact us
Join the community
to join the community
Try Guance
Start online and pay only for what you use.
Get startedChoose a Guance plan