docker get container IP address
Quick Answer
# Get a container's IP on the default bridge
docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' my-container
# Shorter alias
docker inspect my-container | grep -i ipaddress
Usage
You need to know the IP address of a container for debugging or direct connection.
Other causes & fixes
IP on a specific named network
# Replace "my-net" with your network name
docker inspect -f '{{(index .NetworkSettings.Networks "my-net").IPAddress}}' my-container
List all IPs for all running containers
docker inspect $(docker ps -q) --format '{{.Name}}: {{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}'
Get IP from inside the container
docker exec my-container hostname -i
# or
docker exec my-container ip addr show eth0
Prefer container names over IPs
On user-defined networks, containers resolve each other by name — more reliable than IP.
# Use the service/container name in connection strings
DATABASE_URL=postgres://db:5432/mydb # "db" is the container name
Related