docker-py
docker-py copied to clipboard
I can not get my container's IP address.
I started a container with python sdk, but the sdk cannot obtain the network information of the container (other information is correct), but the network information can be viewed correctly using docker inspect. Help!
It'll be in container.attrs['NetworkSettings']['IPAddress']
Yeah I've a problem with this also.
I take a look a the output for docker inspect <container name> and I can see the "IPAddress" key with an IP address-like value
When I take the container.attrs['NetworkSettings']['IPAddress'] as suggested, it is an empty string.
I'm using PyCharm and I've searched the container object in the debug window for what I know the IP address should be (from docker inspect output) but there is no result for the search
@eoinmarron
I take a look a the output for docker inspect
and I can see the "IPAddress" key with an IP address-like value When I take the container.attrs['NetworkSettings']['IPAddress'] as suggested, it is an empty string.
Exactly the same for me. docker inspect will show me the IP address while the container.attrs won't. I have double checked, the container ID in both docker inspect and container.attrs is exactly the same.
So container.attrs appears to be just a snapshot and does not update as the container state changes. In my case, container.attrs was kept at status created without an IP. Refreshing it with something like container = client.containers.get(container.attrs['Id']) would actually reveal a running state, and an IP address.
You need to call container.reload() for the container object to reflect the current state of the docker container. This also holds true for the other kinds of docker objects like volumes or networks.