I started up a Docker Container using this command docker run alpine /bin/echo 'Hello world'
which created a container when I looked within docker ps -a
.
I grabbed the Container ID and tried to inspect the IP Address by executing sudo docker inspect <container id> | grep 'IPAddress'
which returned the IP Address as empty / null.
Any idea why it is giving no IP Address when the container should be automatically assigned an IP Address once created?
CodePudding user response:
I just looked at a random stopped container of mine, and it also showed an empty string for IPAddress, when I know for a fact it had an IPAddress while it was running.
It is almost certainly the case that the reason you have no IPAddress is that your container is not actively running. It immediately exists after echoing 'Hello world'.
CodePudding user response:
Your image will echo the message and then exit (docker ps will not list it as running). docker inspect
will also report it not running (status -> exited).
If you replace your command with:
docker run alpine yes
(oh, yes... so the container keeps running)
The container will surely have a valid IP address until you docker stop
it.