-
Notifications
You must be signed in to change notification settings - Fork 1.7k
dockerClient.containers.create(..., ports={...: None}) does not work in docker client 3.2.0 and upwards #2792
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi @bentheiii First of all, thank you for the code snippet. The containers documentation explain how ports should be used:
I could not reproduce the empty list on Linux, so I suggest you print the Have a nice day :) PS: I'm preparing a windows machine to try to reproduce the problem. |
Hi and thanks for the quick reply, I can reproduce the problem on multiple machines (windows and mac)
|
Hi @bentheiii Sorry to ask you again, but the attempt to recover my windows machine was a total failure. Could you add a print right before reloading the container to be sure that is happening since the container creation? 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()
+ portmap = container.attrs["NetworkSettings"]["Ports"]
+ print(portmap)
container.reload()
portmap = container.attrs["NetworkSettings"]["Ports"]
print(portmap)
finally:
container.kill('SIGKILL') In the meanwhile, I will figure out how to debug that. Thanks and have a nice day :) |
Hello, I have run the following code:
this is the result:
filtering only
EDIT: I'm just now noticing the strange behaviour, will investigate further if I have time |
It appears that the issue can be fixed by introducing a small delay (even a function call) between the client = DockerClient.from_env()
container = client.containers.create("redis:latest", detach=True, ports={11234: None})
def report(label):
attrs = container.attrs
portmap = attrs["NetworkSettings"]["Ports"]
print(label, 'all attrs', attrs)
print(label, 'portmap', portmap)
try:
report('A')
container.start()
container.reload()
report('B')
container.reload()
report('C')
finally:
container.kill('SIGKILL') output:
|
My output (linux) was: A portmap {}
B portmap {'11234/tcp': [{'HostIp': '0.0.0.0', 'HostPort': '49155'}], '6379/tcp': None}
C portmap {'11234/tcp': [{'HostIp': '0.0.0.0', 'HostPort': '49155'}], '6379/tcp': None} @ulyssessouza could you try that as well? Thanks @bentheiii @ulyssessouza |
Hi @bentheiii I´m sorry to ask you again, but could you try to play around with Unfortunately, that issue doesn't happen on Linux, and Docker doesn´t work inside a Windows VM. Thanks again, and have a nice day :) |
I think this is a Docker Desktop issue, so this should be in the docker for-mac/for-win repository? |
SDK version: 4.4.4
OS: Windows, also reproduced in WSL, and mac
python version: 3.8
reproduced in the following docker versions:
The following code snippet:
prints an empty list
[]
on docker client versions 3.20 onwards, and a list of host ports/ips for earlier versions.The text was updated successfully, but these errors were encountered: