Can't set network alias upon container creation
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 7.2k
- Forks
- 1.7k
- Avg merge
- 13d 8h
- Merged PRs (30d)
- 2
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in docker/models/containers.py at line 1077 and compare the SDK's container creation arguments with the Docker API's networking_config structure and the CLI's --network-alias option. Done means creating a container on a custom network with its network alias configured directly, without requiring a later connect and disconnect sequence.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- docker, python
- Domain
- api, networking
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100