Skip to content

Presentation of host-port of services with a randomly assigned port is incorrect #402

Description

@thaJeztah

Description

When specifying only the container port when publishing a port (-p <container-port>), the randomly assigned host-port is not visible in docker service ls, and 0 is shown instead.

Steps to reproduce the issue:

Create two services with a port published; one with a fixed host-port, one with a randomly assigned host-port;

$ docker service create -p 1234:80 --name with-fixed-port nginx:alpine
$ docker service create -p 80 --name with-random-port nginx:alpine

Inspect the service with a randomly assigned host-port;

$ docker service inspect -f '{{json .Endpoint.Spec.Ports}} {{json .Endpoint.Ports}}' with-random-port | jq .

[
  {
    "Protocol": "tcp",
    "TargetPort": 80,
    "PublishMode": "ingress"
  }
]
[
  {
    "Protocol": "tcp",
    "TargetPort": 80,
    "PublishedPort": 30000,
    "PublishMode": "ingress"
  }
]

Run docker service ls

$ docker service ls

ID                  NAME                MODE                REPLICAS            IMAGE               PORTS
5d44i665qj66        with-random-port    replicated          1/1                 nginx:alpine        *:0->80/tcp
j7161oundh9s        with-fixed-port     replicated          1/1                 nginx:alpine        *:1234->80/tcp

Describe the results you received:

The service's "random" host port is (probably) taken from the services .Endpoint.Spec, and presented as *:0->80/tcp

Describe the results you expected:

The "random" port should be taken from the service's Endpoint.Ports, and presented as *:30000->80/tcp

Additional information you deem important (e.g. issue happens only occasionally):

Always reproducible

Output of docker version:

Client:
 Version:      17.06.1-ce-rc1
 API version:  1.30
 Go version:   go1.8.3
 Git commit:   77b4dce
 Built:        Fri Jul 14 07:38:15 2017
 OS/Arch:      darwin/amd64

Server:
 Version:      17.06.1-ce-rc1
 API version:  1.30 (minimum version 1.12)
 Go version:   go1.8.3
 Git commit:   77b4dce
 Built:        Fri Jul 14 07:33:35 2017
 OS/Arch:      linux/amd64
 Experimental: true

Output of docker info:

Containers: 3
 Running: 2
 Paused: 0
 Stopped: 1
Images: 501
Server Version: 17.06.1-ce-rc1
Storage Driver: overlay2
 Backing Filesystem: extfs
 Supports d_type: true
 Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: bridge host ipvlan macvlan null overlay
 Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
Swarm: active
 NodeID: drfinwj2um6lv0pbprh0gzzfm
 Is Manager: true
 ClusterID: 1nfnet5qybgsy264nxp3of5tk
 Managers: 1
 Nodes: 1
 Orchestration:
  Task History Retention Limit: 5
 Raft:
  Snapshot Interval: 10000
  Number of Old Snapshots to Retain: 0
  Heartbeat Tick: 1
  Election Tick: 3
 Dispatcher:
  Heartbeat Period: 5 seconds
 CA Configuration:
  Expiry Duration: 3 months
  Force Rotate: 0
 Root Rotation In Progress: false
 Node Address: 192.168.65.2
 Manager Addresses:
  192.168.65.2:2377
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 6e23458c129b551d5c9871e5174f6b1b7f6d1170
runc version: 810190ceaa507aa2727d7ae6f4790c76ec150bd2
init version: 949e6fa
Security Options:
 seccomp
  Profile: default
Kernel Version: 4.9.36-moby
Operating System: Alpine Linux v3.5
OSType: linux
Architecture: x86_64
CPUs: 4
Total Memory: 1.952GiB
Name: moby
ID: 3RWB:O2US:ECBD:52GT:6CQY:7DPT:DP3F:ZFLC:BLEV:WVRD:FILS:ZT2D
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): true
 File Descriptors: 58
 Goroutines: 198
 System Time: 2017-07-31T21:18:13.405603434Z
 EventsListeners: 3
No Proxy: *.local, 169.254/16
Registry: https://index.docker.io/v1/
Experimental: true
Insecure Registries:
 127.0.0.0/8
Live Restore Enabled: false

Additional environment details (AWS, VirtualBox, physical, etc.):

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions