Skip to content
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

port forwarding from windows CLI resulted in an unexpected dynamic port number #5433

Closed
mike-reilly-bg opened this issue Sep 12, 2024 · 3 comments

Comments

@mike-reilly-bg
Copy link

Description

I ran a container with this command:

docker run -p 8250:8260 -it --name temp --privileged dev_container /sbin/init

and expected the host and container ports 8250 and 8260 to bind (or possibly vice-versa?), but instead I got a random port number (as seen from docker inspect). I confirmed that the new host port number, 5906, was the one that actually functioned for the forwarding.

It is possible that I do not understand the intended functionality, but from what I read this seems unexpected. If this is expected behavior, perhaps the help section would benefit from being more explicit.

docker inspect temp output snippet:

"Ports": {
                "8250/tcp": null,
                "8260/tcp": [
                    {
                        "HostIp": "0.0.0.0",
                        "HostPort": "5906"
                    }
                ]
            },

Full docker inspect temp output:

C:\Windows\system32> docker inspect temp
[
    {
        "Id": "8ff1852a9bf4cfc89d9ab6e8c5de287be9fe50f3c46590b4c485b5ec557f374b",
        "Created": "2024-09-12T23:10:51.276888692Z",
        "Path": "/sbin/init",
        "Args": [],
        "State": {
            "Status": "running",
            "Running": true,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 442,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2024-09-12T23:10:51.937474367Z",
            "FinishedAt": "0001-01-01T00:00:00Z"
        },
        "Image": "sha256:6b80a15c16639be595a283605bea9103db98f7a1de0695701e0f7cb499e27d72",
        "ResolvConfPath": "/var/lib/docker/containers/8ff1852a9bf4cfc89d9ab6e8c5de287be9fe50f3c46590b4c485b5ec557f374b/resolv.conf",
        "HostnamePath": "/var/lib/docker/containers/8ff1852a9bf4cfc89d9ab6e8c5de287be9fe50f3c46590b4c485b5ec557f374b/hostname",
        "HostsPath": "/var/lib/docker/containers/8ff1852a9bf4cfc89d9ab6e8c5de287be9fe50f3c46590b4c485b5ec557f374b/hosts",
        "LogPath": "/var/lib/docker/containers/8ff1852a9bf4cfc89d9ab6e8c5de287be9fe50f3c46590b4c485b5ec557f374b/8ff1852a9bf4cfc89d9ab6e8c5de287be9fe50f3c46590b4c485b5ec557f374b-json.log",
        "Name": "/temp",
        "RestartCount": 0,
        "Driver": "overlay2",
        "Platform": "linux",
        "MountLabel": "",
        "ProcessLabel": "",
        "AppArmorProfile": "",
        "ExecIDs": null,
        "HostConfig": {
            "Binds": null,
            "ContainerIDFile": "",
            "LogConfig": {
                "Type": "json-file",
                "Config": {}
            },
            "NetworkMode": "bridge",
            "PortBindings": {
                "8260/tcp": [
                    {
                        "HostIp": "0.0.0.0",
                        "HostPort": "0"
                    }
                ]
            },
            "RestartPolicy": {
                "Name": "no",
                "MaximumRetryCount": 0
            },
            "AutoRemove": false,
            "VolumeDriver": "",
            "VolumesFrom": null,
            "ConsoleSize": [
                47,
                156
            ],
            "CapAdd": null,
            "CapDrop": null,
            "CgroupnsMode": "host",
            "Dns": [],
            "DnsOptions": [],
            "DnsSearch": [],
            "ExtraHosts": null,
            "GroupAdd": null,
            "IpcMode": "private",
            "Cgroup": "",
            "Links": null,
            "OomScoreAdj": 0,
            "PidMode": "",
            "Privileged": true,
            "PublishAllPorts": false,
            "ReadonlyRootfs": false,
            "SecurityOpt": [
                "label=disable"
            ],
            "UTSMode": "",
            "UsernsMode": "",
            "ShmSize": 67108864,
            "Runtime": "runc",
            "Isolation": "",
            "CpuShares": 0,
            "Memory": 0,
            "NanoCpus": 0,
            "CgroupParent": "",
            "BlkioWeight": 0,
            "BlkioWeightDevice": [],
            "BlkioDeviceReadBps": [],
            "BlkioDeviceWriteBps": [],
            "BlkioDeviceReadIOps": [],
            "BlkioDeviceWriteIOps": [],
            "CpuPeriod": 0,
            "CpuQuota": 0,
            "CpuRealtimePeriod": 0,
            "CpuRealtimeRuntime": 0,
            "CpusetCpus": "",
            "CpusetMems": "",
            "Devices": [],
            "DeviceCgroupRules": null,
            "DeviceRequests": null,
            "MemoryReservation": 0,
            "MemorySwap": 0,
            "MemorySwappiness": null,
            "OomKillDisable": false,
            "PidsLimit": null,
            "Ulimits": [],
            "CpuCount": 0,
            "CpuPercent": 0,
            "IOMaximumIOps": 0,
            "IOMaximumBandwidth": 0,
            "MaskedPaths": null,
            "ReadonlyPaths": null
        },
        "GraphDriver": {
            "Data": {
                "LowerDir": "/var/lib/docker/overlay2/0dbf90a824f01e8afbbf77b319d0b23f3e5da42d0b41c7c568f39413df6719f4-init/diff:/var/lib/docker/overlay2/74fd4a506d93ba7f75c924901fba0b92fde6f3b464c3f5dbad1f2fd8792237eb/diff:/var/lib/docker/overlay2/023d8596d52470294687aa6c8175a0ac14df64f6928ea3d4819628676073d3ea/diff:/var/lib/docker/overlay2/dd9903d78f77d4588fc9a6cc74d606edf7e88da4be9c4087540e2f5fb99bdfde/diff:/var/lib/docker/overlay2/d415bb73be129df20bad6a39b831cd854b8b1db42a9c82bd09c609f21b88fe89/diff:/var/lib/docker/overlay2/62604106ddb001d7fb8430fb2afaaa8c5d17c0c1b8a90eb22446e9313c24afe9/diff:/var/lib/docker/overlay2/12130ce8fb4e8622b0e51394903ac462ff00ca470a71d1db35be6aa4aa3a4273/diff:/var/lib/docker/overlay2/8505da43ecc01c675314c1117e6aa50a3dd911d0e8e8a3305d5d411e47dce79d/diff:/var/lib/docker/overlay2/0b49e3abf0175df4874d6e694fda33c9b9b412500b7d39587e590f9ce3937baa/diff:/var/lib/docker/overlay2/56be346054ab466565ecbb0e2397e7ef6d8d24cd3788b2dccfb744f66deb4ab5/diff:/var/lib/docker/overlay2/097d4dcf687ac16f2f80ee57fbce7b2e2f3b7c604f45358d1f374d459ca52683/diff:/var/lib/docker/overlay2/2db4d0d58b56863fb5f61a33da5693e80e4dd9dd57905d8ddf704cab9ca638ff/diff",
                "MergedDir": "/var/lib/docker/overlay2/0dbf90a824f01e8afbbf77b319d0b23f3e5da42d0b41c7c568f39413df6719f4/merged",
                "UpperDir": "/var/lib/docker/overlay2/0dbf90a824f01e8afbbf77b319d0b23f3e5da42d0b41c7c568f39413df6719f4/diff",
                "WorkDir": "/var/lib/docker/overlay2/0dbf90a824f01e8afbbf77b319d0b23f3e5da42d0b41c7c568f39413df6719f4/work"
            },
            "Name": "overlay2"
        },
        "Mounts": [],
        "Config": {
            "Hostname": "8ff1852a9bf4",
            "Domainname": "",
            "User": "",
            "AttachStdin": true,
            "AttachStdout": true,
            "AttachStderr": true,
            "ExposedPorts": {
                "8250/tcp": {},
                "8260/tcp": {}
            },
            "Tty": true,
            "OpenStdin": true,
            "StdinOnce": true,
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
            ],
            "Cmd": [
                "/sbin/init"
            ],
            "Image": "dev_container",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": null,
            "OnBuild": null,
            "Labels": {
                "org.opencontainers.image.ref.name": "ubuntu",
                "org.opencontainers.image.version": "22.04"
            }
        },
        "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "70d81435a447c76b859ca6ff3be320d509cf722602fa6acfd166b53c1c025300",
            "SandboxKey": "/var/run/docker/netns/70d81435a447",
            "Ports": {
                "8250/tcp": null,
                "8260/tcp": [
                    {
                        "HostIp": "0.0.0.0",
                        "HostPort": "5906"
                    }
                ]
            },
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "3e1136dac0b1e8b01ca86522740765065e14657afe035e964ee9c2ab27c60544",
            "Gateway": "172.17.0.1",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "172.17.0.2",
            "IPPrefixLen": 16,
            "IPv6Gateway": "",
            "MacAddress": "02:42:ac:11:00:02",
            "Networks": {
                "bridge": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": null,
                    "MacAddress": "02:42:ac:11:00:02",
                    "DriverOpts": null,
                    "NetworkID": "1c7aed8f866ecafc3227ffbf9e5a02d5249b65f154ae62cc9c4afd25a3942c0b",
                    "EndpointID": "3e1136dac0b1e8b01ca86522740765065e14657afe035e964ee9c2ab27c60544",
                    "Gateway": "172.17.0.1",
                    "IPAddress": "172.17.0.2",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "DNSNames": null
                }
            }
        }
    }
]

Reproduce

Environment (not sure what details are relevant):
Windows 10
WSL2
Ubuntu 22.04 - derived image named dev_container

docker run -p 8250:8260 -it --name temp --privileged dev_container /sbin/init
docker inspect temp

Expected behavior

I expected Docker to bind host and container ports 8250 and 8260 (or possibly the other way around), but instead container port 8260 was bound to host port 5906.

docker version

Client:
 Version:           27.2.0
 API version:       1.47
 Go version:        go1.21.13
 Git commit:        3ab4256
 Built:             Tue Aug 27 14:17:17 2024
 OS/Arch:           windows/amd64
 Context:           desktop-linux

Server: Docker Desktop 4.34.2 (167172)
 Engine:
  Version:          27.2.0
  API version:      1.47 (minimum version 1.24)
  Go version:       go1.21.13
  Git commit:       3ab5c7d
  Built:            Tue Aug 27 14:15:15 2024
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.7.20
  GitCommit:        8fc6bcff51318944179630522a095cc9dbf9f353
 runc:
  Version:          1.1.13
  GitCommit:        v1.1.13-0-g58aa920
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

docker info

Client:
 Version:    27.2.0
 Context:    desktop-linux
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.16.2-desktop.1
    Path:     C:\Program Files\Docker\cli-plugins\docker-buildx.exe
  compose: Docker Compose (Docker Inc.)
    Version:  v2.29.2-desktop.2
    Path:     C:\Program Files\Docker\cli-plugins\docker-compose.exe
  debug: Get a shell into any image or container (Docker Inc.)
    Version:  0.0.34
    Path:     C:\Program Files\Docker\cli-plugins\docker-debug.exe
  desktop: Docker Desktop commands (Alpha) (Docker Inc.)
    Version:  v0.0.15
    Path:     C:\Program Files\Docker\cli-plugins\docker-desktop.exe
  dev: Docker Dev Environments (Docker Inc.)
    Version:  v0.1.2
    Path:     C:\Program Files\Docker\cli-plugins\docker-dev.exe
  extension: Manages Docker extensions (Docker Inc.)
    Version:  v0.2.25
    Path:     C:\Program Files\Docker\cli-plugins\docker-extension.exe
  feedback: Provide feedback, right in your terminal! (Docker Inc.)
    Version:  v1.0.5
    Path:     C:\Program Files\Docker\cli-plugins\docker-feedback.exe
  init: Creates Docker-related starter files for your project (Docker Inc.)
    Version:  v1.3.0
    Path:     C:\Program Files\Docker\cli-plugins\docker-init.exe
  sbom: View the packaged-based Software Bill Of Materials (SBOM) for an image (Anchore Inc.)
    Version:  0.6.0
    Path:     C:\Program Files\Docker\cli-plugins\docker-sbom.exe
  scout: Docker Scout (Docker Inc.)
    Version:  v1.13.0
    Path:     C:\Program Files\Docker\cli-plugins\docker-scout.exe

Server:
 Containers: 1
  Running: 1
  Paused: 0
  Stopped: 0
 Images: 12
 Server Version: 27.2.0
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Using metacopy: false
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 1
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 nvidia runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 8fc6bcff51318944179630522a095cc9dbf9f353
 runc version: v1.1.13-0-g58aa920
 init version: de40ad0
 Security Options:
  seccomp
   Profile: unconfined
 Kernel Version: 5.15.153.1-microsoft-standard-WSL2
 Operating System: Docker Desktop
 OSType: linux
 Architecture: x86_64
 CPUs: 12
 Total Memory: 15.5GiB
 Name: docker-desktop
 ID: e4b30eb8-0049-4303-abf2-54dd12f9400c
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 HTTP Proxy: http.docker.internal:3128
 HTTPS Proxy: http.docker.internal:3128
 No Proxy: hubproxy.docker.internal
 Labels:
  com.docker.desktop.address=npipe://\\.\pipe\docker_cli
 Experimental: false
 Insecure Registries:
  hubproxy.docker.internal:5555
  127.0.0.0/8
 Live Restore Enabled: false

WARNING: No blkio throttle.read_bps_device support
WARNING: No blkio throttle.write_bps_device support
WARNING: No blkio throttle.read_iops_device support
WARNING: No blkio throttle.write_iops_device support
WARNING: daemon is not using the default seccomp profile

Additional Info

Windows 10 Pro
Version 10.0.19045 Build 19045

@akerouanton
Copy link
Member

Hey @mike-reilly-bg, thanks for reporting this issue.

I see you're running Docker Desktop, so this issue has to be re-open in https://github.com/docker/for-win. This is the repo we use to track Docker Desktop issues on Windows. When you open a new issue there, could you please link to this issue?

FWIW, I'm currently rewriting a good chunk of Docker Desktop's port forwarder. I don't see what could cause this issue but I think it'll disappear once my rewrite is out. Hopefully it should be included in the next release. It'd still be valuable if you could recreate that issue there and report if things work correctly once v4.35 is out.

In the meantime, let me close this issue.

@toothless92
Copy link

Thanks @akerouanton for the reply!

Opened docker/for-win#14317

@mike-reilly-bg
Copy link
Author

whoops, responded with my other account

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants