Skip to content
System

Find the IP address of a Docker container on Linux

Avatar illustré de Julien Macé 5 min read
Modules de conteneurs reliés à deux réseaux sur un serveur Linux
Illustration générée du rattachement de conteneurs à plusieurs réseaux, sans représenter une topologie réellement mesurée.

A docker inspect command may display several addresses, or no IPv4 address in the field you’re used to checking. Before copying a value into a URL, identify which network it belongs to and which host is actually running Docker. The command below displays one line per network with IPv4 and IPv6 addresses. It does not modify the container or its network.

Modules de conteneurs reliés à plusieurs réseaux sur un serveur Linux

Identify the container and Docker engine

Start by checking the context, then find the container by its name or ID:

docker context show
docker ps -a --format 'table {{.ID}}\t{{.Names}}\t{{.Status}}\t{{.Ports}}'

In the following commands, replace NOM_OU_ID_A_REMPLACER with the name or ID actually displayed:

CONTENEUR='NOM_OU_ID_A_REMPLACER'
docker inspect --type=container --format '{{.Name}} status={{.State.Status}} mode={{.HostConfig.NetworkMode}}' "$CONTENEUR"

docker ps -a includes stopped containers. A stopped container may retain inspection information, but seeing an address does not mean that a service is currently available.

The client may also be talking to a remote daemon. In that case, the “Docker host” is the daemon’s machine, not necessarily the computer where you enter the commands. docker context show displays the selected context; environment variables can also affect the target. Do not publish these variables or the full output of docker inspect: it may contain sensitive data.

Display the IP address for each network

For the selected container, run:

docker inspect --type=container --format '{{range $nom, $reseau := .NetworkSettings.Networks}}{{printf "%s\tIPv4=%s\tIPv6=%s\n" $nom $reseau.IPAddress $reseau.GlobalIPv6Address}}{{end}}' "$CONTENEUR"

The expected output is one line per network attachment, showing the network name and the IPv4 and IPv6 fields. Their values may be empty. An empty IPv4 field therefore does not mean that no IPv6 address exists. The address belongs to a network attachment; a container connected to multiple networks may have several addresses.

To extract the IPv4 address for a specific network, replace NOM_RESEAU_A_REMPLACER in the template with the name found in the first command:

docker inspect --type=container --format '{{with index .NetworkSettings.Networks "NOM_RESEAU_A_REMPLACER"}}{{.IPAddress}}{{else}}network absent{{end}}' "$CONTENEUR"

The message network absent means that this name is not attached to the container. If the network exists but uses IPv6 only, the IPv4 extraction may still be empty. In that case, return to the full output. For an IPv6 address, use the IPv6 value from the first command and check the format expected by the application that receives it.

Cross-check the address on the network

Use the exact network name, which may be prefixed with the Compose project name:

RESEAU='NOM_RESEAU_A_REMPLACER'
docker network ls
docker network inspect --format '{{.Name}} driver={{.Driver}}' "$RESEAU"
docker network inspect --format '{{range $id, $c := .Containers}}{{printf "%s\tIPv4=%s\tIPv6=%s\n" $c.Name $c.IPv4Address $c.IPv6Address}}{{end}}' "$RESEAU"

This view lets you match each container to its addresses on the network. In docker network inspect, IPv4Address may include a CIDR prefix, for example, an address followed by /24. This differs from the address-only output provided by docker inspect.

Inspection commands are read-only. If Docker denies access to the engine, stop there: do not change the socket permissions or modify group membership to bypass the denial.

Choose between an internal IP and a published port

The right starting point depends on where you are accessing the service from.

With native Linux Docker Engine and a bridge network, the internal address is used for communication on that network and, in the standard case, from the engine host. From another machine on the LAN, generally use that host’s address and an already published port. Direct-routing configurations and other drivers exist; this procedure cannot determine whether they are in use.

Check existing port publications with:

docker port "$CONTENEUR"

This command displays existing port mappings. It does not provide the container’s IP address or create a publication. 0.0.0.0 and :: are generic listening addresses; do not copy them as the destination in a URL. EXPOSE in an image does not mean that a port is published on the host.

Docker Desktop on Linux runs the engine in a virtual machine. An internal address visible with inspect therefore does not guarantee direct access from the physical machine. In that case, first check the already published port and the host address.

In rootless mode, the address may belong to the RootlessKit namespace and may not be directly reachable from outside that namespace. The result depends on the mode and version; do not disable isolation just to get an address that is easier to use.

Two network modes also explain why there may be no dedicated address. In native host mode, the container shares the engine host’s network namespace: check that host’s addresses and the service’s ports. In none mode, the loopback interface remains local to the namespace; 127.0.0.1 is not a destination to copy from the host.

Check a service without modifying the network

An IP address does not prove that a service is listening or responding. For a known HTTP service, replace the entire URL, including the address, port, and path, with a real read-only target:

URL_SERVICE='http://ADDRESS_TO_REPLACE:PORT_TO_REPLACE/PATH_TO_REPLACE'
curl --connect-timeout 3 --max-time 5 --silent --show-error --output /dev/null --write-out 'HTTP %{http_code}\n' "$URL_SERVICE"

From a location that can reach the internal network, use the container’s address and the service’s internal port. From the host or LAN, use the host’s address and the appropriate published port. For a literal IPv6 address in a URL, enclose the address in square brackets. Use this request only with a known read-only endpoint: an HTTP request may be logged or have side effects, depending on the application.

An HTTP status code indicates that a service or intermediary responded; 401, 403, or 404 do not mean that the network is missing. A timeout alone does not pinpoint the cause, and HTTP 000 is not a status code received from the server. ping checks only ICMP: its failure does not prove that a TCP or HTTP service is unreachable, and its success does not confirm that the service is working.

For ongoing communication between services on a custom Docker network or with Compose, prefer using the service name and its internal port rather than hard-coding a dynamic IP address. Recreating a container may assign it a different address. If you have identified the target but the service is not responding, continue troubleshooting separately, for example by checking the Docker Compose service logs, without changing the network at random.

To distinguish the container’s address from the host’s addresses, you can also check Linux addresses with ip addr. If the HTTP check fails, see how to interpret a URL test with curl.

Sources: docker inspect, bridge network, Docker Desktop networking, rootless mode limitations, Docker Compose networking.

Share Facebook X WhatsApp LinkedIn Pinterest Reddit Email