docker / docker/docker-py

dockerClient.containers.create(..., ports={...: None}) does not work in docker client 3.2.0 and upwards

Open
#2,792 8 comments 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

SDK version: 4.4.4
OS: Windows, also reproduced in WSL, and mac
python version: 3.8
reproduced in the following docker versions:

  • client: 3.2.2, engine: 20.10.5
  • client: 3.2.1, engine: 20.10.5
  • client: 3.2.0, engine: 20.10.2

The following code snippet:

client = DockerClient.from_env()
client.images.pull("redis:latest", platform=None)
container = client.containers.create("redis:latest", detach=True, ports={11234: None})
try:
    container.start()
    container.reload()
    portmap = container.attrs["NetworkSettings"]["Ports"]
    print(portmap['11234/tcp'])
finally:
    container.kill('SIGKILL')

prints an empty list [] on docker client versions 3.20 onwards, and a list of host ports/ips for earlier versions.

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

Start by running the provided DockerClient.from_env and containers.create reproduction with ports={11234: None} across the listed client and engine versions. Trace the containers.create, container.start, container.reload, and NetworkSettings["Ports"] entry points to compare the returned port mapping. Done means the expected host ports and IPs are returned again for Docker client 3.2.0 and later.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, python
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.