docker / docker/docker-py

equivalent Method to select a host port from a range when publishing a container port

Open
#2,915 1 comment 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.