equivalent Method to select a host port from a range when publishing a container port
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 7.2k
- Forks
- 1.7k
- Avg merge
- 13d 8h
- Merged PRs (30d)
- 2
Description
When using the CLI, I can specify to publish a container port to a range of host ports - EG:
docker run -d -p 9200-9201:9200 some-image
https://docs.docker.com/network/links/
this will expose the container port 9200 on a randomly selected port on the host (in this example, either 9200 or 9201).
It seems the docker SDK does not support similar functionality. If I pass something like this to the create method:
ports= {
"9200/tcp": [9200, 9201],
}
this will result in the container port 9200 being published to BOTH host ports, which is undesirable for my use case. Is there some way to enable the behavior via the SDK that the CLI supports, where only 1 port will be selected?
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
Trace the SDK's create method and its ports handling, then compare them with the Docker CLI -p range syntax and Docker Engine API port-publishing behavior. Confirm whether one host port can be selected from 9200-9201; if support is added, verify that only one of those ports is bound.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- docker, python
- Domain
- api, devops
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100