Docker-py: networks argument to containers.run()

Created on 1 Feb 2017  路  4Comments  路  Source: docker/docker-py

I am doing:

api.containers.run(
    ...,
    networks=['foo']
)

This has no effect. The container will instead be part of the default bridge.

The command apparently sends this to the API:

{...,
'NetworkingConfig': {'foo': None}
}

What is the correct way to use this?

kinbug levedockerclient

Most helpful comment

Hi,

Unfortunately that looks like a bug on our end. I believe you should be able to do the same thing using the network_mode parameter, i.e

api.containers.run(
  ...
  network_mode='foo'
)

Hope that helps

All 4 comments

Hi,

Unfortunately that looks like a bug on our end. I believe you should be able to do the same thing using the network_mode parameter, i.e

api.containers.run(
  ...
  network_mode='foo'
)

Hope that helps

Was affected by this bug/unexpected usage today but @shin-'s suggestion worked.

````
import docker

client = docker.from_env()

network = client.networks.create("mynetwork")

Expected to work but does not

c1 = client.containers.run('alpine', 'echo hello', detach=True, name="c1", networks=[network.name])

c2 = client.containers.run('alpine', 'echo hello', detach=True, name="c2", networks=[network.name])

Does work

c1 = client.containers.run('alpine', 'echo hello', detach=True, name="c1", network_mode=network.name)
c2 = client.containers.run('alpine', 'echo hello', detach=True, name="c2", network_mode=network.name)

network.reload()
print network.containers
````

Why is this closed? How is networks supposed to be used? The documentation should be updated for both params, as this is not clear in any way.

  • This is closed because a fix has been merged in master.
  • networks will be removed in the next release, as it has never worked to begin with.
  • The documentation is updated in master along with the code itself.
Was this page helpful?
0 / 5 - 0 ratings