docker-py icon indicating copy to clipboard operation
docker-py copied to clipboard

Container.attrs["State"]["Running"] remains False after starting a container

Open emendir opened this issue 1 year ago • 1 comments

After creating a Container object and starting it, the container's attrs field still says the container is not running. Only when creating a new Container object does the attrs field show the correct status.

I wonder if any other fields of the attrs attribute are affected?

Here is ascript demonstrating the problem:

import docker
from time import sleep
client = docker.from_env()

container = client.containers.create("nginx")

container.start()
sleep(5)

print(container.attrs["State"]["Running"]) # prints False
print(client.containers.get(container.id).attrs["State"]["Running"]) # prints True

emendir avatar Jun 06 '24 06:06 emendir

This is intended behaviour, see the docs: https://docker-py.readthedocs.io/en/stable/containers.html#container-objects

Note that local attributes are cached; users may call reload() to query the Docker daemon for the current properties, causing attrs to be refreshed.

massi1008 avatar Jul 01 '24 08:07 massi1008