You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Description
Via the Go SDK, I'm creating & starting a container with several ports that I want bound to the host, and I don't want to deal with choosing the host ports so I let Docker do it for me. I therefore need to inspect the container after it's created to figure out what host ports the container got. Approximately 10% of the time, I'll inspect the container after creation and NetworkSettings.Ports will have my requested ports as keys but there won't be any values:
In the Go SDK, create a nat.PortMap object with some ports to bind, with the value set to []nat.PortBinding{{}} so that Docker will automatically pick the host port
Create the container with the HostConfig.PortBindings field set to the port map
Immediately afterwards, inspect the running container to try and find the host interface:portnum mappings
Approximately 10% of the time, NetworkSettings.Ports will have keys corresponding to your ports but no values. Doing the same inspect later will work.
Describe the results you received: NetworkSettings.Ports map has no values
Describe the results you expected: NetworkSettings.Ports should always have values if the container creation & starting succeeded
Additional information you deem important (e.g. issue happens only occasionally):
This happens nondeterministically, which suggests to me that the Docker Go SDK returns a "success" from starting the container before the host ports are actually bound (which seems like a bug to me).
Output of docker version:
Client:
Cloud integration: 1.0.17
Version: 20.10.7
API version: 1.41
Go version: go1.16.4
Git commit: f0df350
Built: Wed Jun 2 11:56:22 2021
OS/Arch: darwin/amd64
Context: desktop-linux
Experimental: true
Server: Docker Engine - Community
Engine:
Version: 20.10.7
API version: 1.41 (minimum version 1.12)
Go version: go1.13.15
Git commit: b0f5bc3
Built: Wed Jun 2 11:54:58 2021
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.4.6
GitCommit: d71fcd7d8303cbf684402823e425e9dd2e99285d
runc:
Version: 1.0.0-rc95
GitCommit: b9ee9c6314599f1b4a7f497e1f1f856fe433d3b7
docker-init:
Version: 0.19.0
GitCommit: de40ad0
. I therefore need to inspect the container after it's created to figure out what host ports the container got. Approximately 10% of the time, I'll inspect the container after creation
Do you have a minimal code example?
If I'm not mistaken, networking will be attached on container start (not create), and I think it should be synchronous (so after container start, the ephemeral ports should be assigned);
I see you are running on Docker Desktop; I know there's some rewriting happening on container inspect responses when using Docker Desktop (to make the inspect response match the networking setup needed for Docker Desktop);
Would it be able for you to test your code in a container, and in that container, bind-mount /var/run/docker.sock.raw as the socket to connect with the docker daemon? /var/run/docker.sock.raw allows connecting to the docker engine running in Docker Desktop but without the Docker Desktop proxy (which does the rewriting) in between, so something like;
# mount `/var/run/docker.sock.raw` as `/var/run/docker.sock` inside the container;
docker run -it --rm -v /var/run/docker.sock.raw:/var/run/docker.sock <your container image>
Description
Via the Go SDK, I'm creating & starting a container with several ports that I want bound to the host, and I don't want to deal with choosing the host ports so I let Docker do it for me. I therefore need to inspect the container after it's created to figure out what host ports the container got. Approximately 10% of the time, I'll inspect the container after creation and
NetworkSettings.Ports
will have my requested ports as keys but there won't be any values:When I do a command-line inspect of the same container immediately afterwards, the values show up:
Steps to reproduce the issue:
nat.PortMap
object with some ports to bind, with the value set to[]nat.PortBinding{{}}
so that Docker will automatically pick the host portHostConfig.PortBindings
field set to the port mapApproximately 10% of the time,
NetworkSettings.Ports
will have keys corresponding to your ports but no values. Doing the same inspect later will work.Describe the results you received:
NetworkSettings.Ports
map has no valuesDescribe the results you expected:
NetworkSettings.Ports
should always have values if the container creation & starting succeededAdditional information you deem important (e.g. issue happens only occasionally):
This happens nondeterministically, which suggests to me that the Docker Go SDK returns a "success" from starting the container before the host ports are actually bound (which seems like a bug to me).
Output of
docker version
:Output of
docker info
:Additional environment details (AWS, VirtualBox, physical, etc.):
The text was updated successfully, but these errors were encountered: