Can't set network alias upon container creation
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:
- Run/create a container with default or w/e network
- Connect custom network to container and set alias
- 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.
I had the exact the same issue.
As far as i know the only possibility right now is to use network.connect(container, aliases=[])
I wanted to chime in to say that I would also really appreciate the ability to create a network alias upon container creation.
bump i would love to see this feature in future release
bump I would also appreciate such a feature :)
Hello, it would be really nice to have this feature. Any plans for implementation?