Docker-py: docker containers connected to a network when run won't show up in network_object.containers field

Created on 20 Jan 2019  Â·  5Comments  Â·  Source: docker/docker-py

when running a container with

client.containers.run(.....,
                                 network=net1,
                                 ......)

the container ends up connected to the network, but when calling net1.containers on the network object, it returns an empty list ([])
When re-getting the network object with
client.networks.get(net1_name),
the container shows up.

to reproduce this bug:

  1. create a network object with client.networks.create
  2. run a container with client.containers.run, with parameter network = (the name of the net you created)
  3. check network_object.containers field and see it's empty
  4. do client.networks.get(net1_name) to re-get the object and see that now the container is present in
    checked this issue with two different hosts with different docker versions, both reproduced the bug.
kinquestion levedockerclient

All 5 comments

how come this bug is not even looked at?

how come this bug is not even looked at?

Maintainers have lives too. But also, it helps to include as much information as possible when reporting an issue.

In this particular case, this is not a bug; you simply need to call reload() on the network object to see the updated list of containers.

This might have come out ruder than I meant it, I apologise.. thanks for
the clarification

On Wed, Jan 30, 2019, 7:56 PM Joffrey F <[email protected] wrote:

how come this bug is not even looked at?

Maintainers have lives too. But also, it helps to include as much
information as possible
https://github.com/docker/docker-py/blob/master/CONTRIBUTING.md#reporting-issues
when reporting an issue.

In this particular case, this is not a bug; you simply need to call
reload()
https://docker-py.readthedocs.io/en/stable/networks.html#docker.models.networks.Network.reload
on the network object to see the updated list of containers.

—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/docker/docker-py/issues/2235#issuecomment-459043766,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AWj4AYflja_6IAobVPi_G9PHUEWSbFqCks5vIdzkgaJpZM4aJkZd
.

This produces empty lists

[n.containers for n in client.networks.list()]

This does work, but perhaps I'm missing something - requiring a reload() doesn't seem like expected behavior

>>> for n in [n for n in client.networks.list()]:
...     n.reload()
...     n.containers
... 
[]
[<Container: 24ee0397bb>, <Container: 5fa1b004f7>, <Container: cc0479c0d7>, <Container: e54909439a>, <Container: f1f750c936>]
[<Container: dd9bc262df>]
[]

The list endpoint returns a shortened representation of the Network object, omitting the list of connected containers among other things. You can also use the greedy parameter to load the full data, eg

[n.containers for n in client.networks.list(greedy=True)]
Was this page helpful?
0 / 5 - 0 ratings