question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

refresh container.attrs

See original GitHub issue

Following code runs into a problem:

container = docker.from_env().containers.create(image=...)
container.start()
ip = container.attrs["NetworkSettings"]["Networks"]["bridge"]["IPAddress"]
# ip == "" :(, but I get it.
time.sleep(...)
ip = container.attrs["NetworkSettings"]["Networks"]["bridge"]["IPAddress"]
# ip == "" :(, still ???:-(???

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:6

github_iconTop GitHub Comments

2reactions
ah19commented, Jan 4, 2017

I think this is the same problem that I was about to open an issue for – the documentation for running a container does not mention that Container.attrs is cached (specifically in the detach=True example). The Container.reload method is not mentioned in the documentation (nor is wait by the way), is this an oversight or should it not be called?

my code for running a command in two docker images ended up looking like this:

def run_comparison_cmd(old_image, new_image, command, block=True):
    print("Running command '{}' in containers {}, {}".format(command, old_image, new_image))
    client = docker.from_env()
    old = client.containers.run(old_image, command, detach=True)
    new = client.containers.run(new_image, command, detach=True)

    if block:
        print("Containers started, waiting for them to finish")
        old.wait()
        new.wait()

        #attributes are cached, update them
        old.reload()
        new.reload()

    return old, new

should the wait method on Container be updated to perform a reload before returning?

2reactions
ah19commented, Jan 4, 2017

I have run into a similar problem with myself – try running container.reload()

Read more comments on GitHub >

github_iconTop Results From Across the Web

Containers — Docker SDK for Python 6.0.1 documentation
Detailed configuration may be accessed through the attrs attribute. Note that local attributes are cached; users may call reload() to query the Docker...
Read more >
AttributeContainer | Apple Developer Documentation
AttributeContainer provides a way to store attributes and their values outside of an attributed string. You use this type to initialize an instance...
Read more >
Update a running container - Docker - Stack Overflow
The first command simply restarts the container with your new settings. The second command deletes the old container and creates a new one...
Read more >
Refreshing an Amazon ECS Container Instance Cluster With a ...
In this post, I show you how to manually refresh the container instances in an active ECS cluster with new container instances built...
Read more >
How To Update Docker Container automatically with nearly ...
How to update docker container automatically with Watchtower. Scheduled updates without downtime for your entire docker environment.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found