docker / docker/docker-py

Random port binding not showing up in the .attr object

Open
#1,436 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

kind/question level/dockerclient
Dominant language
Python
Stars
7.2k
Forks
1.7k
Avg merge
13d 8h
Merged PRs (30d)
2

Description

I run a container and use the option ports={8000: None} in order to assign random port binding for this container. I then try to print the container.attr to look for what port did it bind to. It always get empty values: u'PortBindings': {u'8000/tcp': [{u'HostPort': u'', u'HostIp': u''}]}

I use the shell to make sure the container is running and binding ports correctly, and it works just fine. The container is indeed running the ports are bind correctly. But I need to access the port binding from the container object.

What is the problem here?

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 reproducing the issue with the Python ports={8000: None} option, then compare container.attr with the port information shown by the shell while the container is running. No source file or test is named; done means the container object exposes the assigned random host port consistently with the running container.

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
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.