Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Servers, nginx and Docker

docker inspect shows an empty IP address for a container

ErrorThe IP address field is empty for the container

Short answer

A container only has an IP address while it runs and is attached to a bridge-type network. A stopped container has none, the none network gives only a loopback device, and the host network shares the host's own address. Check the state and the network mode first, then read the address from the right network.

  • Applies to Docker Engine 27, Ubuntu 24.04
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    List the container with its state, then read the full inspect output: the network mode and the Networks section name the cause.

    docker ps -a --filter name=<container>
    docker inspect <container>
    docker network inspect bridge
  2. 2Match what you see, then jump to its fix

    1. 1The state is exited or created.The container is not runningFix
    2. 2The network mode is none and the container cannot reach anything.The container was started with --network noneFix
    3. 3The network mode is host and the address field is empty.The container uses the host networkFix
    4. 4docker network inspect bridge does not list the container, but docker ps shows it running.The address is on a user-defined network, not on the default oneFix

What does the error look like?

  • The IP address field is empty for the container
  • docker inspect shows no address for the container

Cause 1 of 4

The container is not running

1Check

Stopped containers lose their IP addresses. The address comes from the network's subnet only while the container is up.

docker ps -a --filter name=<container>

2Fix

Start the container, then read its address.

docker start <container>

3Verify

The address appears in the inspect output.

docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' <container>

Confirmed by docs.docker.com

Did this fix it?

Cause 2 of 4

The container was started with --network none

1Check

With the none driver only the loopback device exists inside the container, and no other interface.

docker inspect <container>   # read the NetworkMode field

2Fix

Recreate the container on a bridge network, for example a user-defined one.

docker network create app-net
docker run -d --name web --network app-net nginx

3Verify

Read the address from the new network.

docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' web

Confirmed by docs.docker.com

Did this fix it?

Cause 3 of 4

The container uses the host network

1Check

With the host driver the container does not get its own IP address, and the application is reachable on the host's address. Options such as -p are ignored.

docker inspect <container>   # read the NetworkMode field

2Fix

Use the host's address, or recreate the container on a bridge network and publish the ports you need.

docker run -d --name web --network app-net -p 8080:80 nginx

3Verify

Request the published port from the host.

curl -I http://localhost:8080

Confirmed by docs.docker.com

Did this fix it?

Cause 4 of 4

The address is on a user-defined network, not on the default one

1Check

Each container gets an address from the subnet of its own network. A container attached to a user-defined network is listed under that network, not under the default bridge.

docker network ls

2Fix

Inspect the network the container is attached to.

docker network inspect app-net

3Verify

The container appears with its address in the output.

docker network inspect app-net

Confirmed by docs.docker.com

Did this fix it?

How do I stop it coming back?

  • Talk to containers by name on a user-defined network instead of by IP address; addresses change when containers restart.
  • Do not hard-code container IPs in configuration.
  • Write the network mode into your run command or Compose file, so nobody has to guess it later.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Servers

A dev container port does not open in the browser when Docker runs on a remote host

If your application only accepts calls from localhost, it will reject connections from published ports

Three things usually break it: the app listens only on localhost inside the container, so published ports are rejected; you open the container port instead of the mapped localhost port VS Code shows; or you changed appPort or a Compose ports list and did not rebuild.

3 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.