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

Can't set network alias upon container creation

Open florpor opened this issue 5 years ago • 6 comments

When creating a container using client.containers.run(...) or client.containers.create(...) there doesn't seem to be a way to set a network alias for the container on its set network. Setting an alias is possible when using a network's connect function, but upon creation some network is already attached to the container (default or otherwise) and will need to be detached if it is unnecessary.

What I am trying to do: run a container, attach it to a single custom network I created and set its alias so other containers on the same network can communicate with it. This is possible to do using the CLI with --network-alias option, and also using the API with the networking_config structure, but based on file docker/models/containers.py line 1077 the SDK does not pass any special network configuration to the API besides the network name.

As far as I can tell the only way to achieve my desired state right now is to:

  1. Run/create a container with default or w/e network
  2. Connect custom network to container and set alias
  3. Find container original network, client.networks.get() it and disconnect the container from it

Am I missing something or is this correct? If it is correct - since the API allows this, can this be added? I can create a pull request if this need is agreeable.

florpor avatar Sep 21 '20 14:09 florpor

I had the exact the same issue.

useminmin avatar Sep 24 '20 04:09 useminmin

As far as i know the only possibility right now is to use network.connect(container, aliases=[])

Manu10744 avatar Dec 18 '20 09:12 Manu10744

I wanted to chime in to say that I would also really appreciate the ability to create a network alias upon container creation.

npel-21 avatar Jun 23 '21 13:06 npel-21

bump i would love to see this feature in future release

Manu10744 avatar Jul 22 '21 07:07 Manu10744

bump I would also appreciate such a feature :)

initBasti avatar Aug 27 '21 15:08 initBasti

Hello, it would be really nice to have this feature. Any plans for implementation?

kranken007 avatar Nov 07 '24 13:11 kranken007