To find a Docker container’s IP address from the host, you can use Docker commands or inspect the container’s details. Here are the primary ways to achieve this:
1. Using docker inspect
The docker inspect
command retrieves detailed information about a container, including its IP address.
- Run
docker inspect
and search for the container’s IP address under theNetworkSettings
section. - This works for containers using the default bridge network or custom networks.
2. Using docker network inspect
If the container is part of a custom network, inspect the network instead:
- List all networks with
docker network ls
. - Use
docker network inspect network_name
to see connected containers and their IP addresses.
3. Using docker exec
Access the container and run a command to check its IP address internally, such as ip addr
or ifconfig
.
4. Using Tools or Scripts
You can automate IP retrieval with scripts or tools like Docker Compose, which can provide service-related network information.
Note:
- If the container uses
host
networking, it shares the host’s network and doesn’t have a separate IP. - Use proper permissions and ensure the container is running before inspecting it.