Skip to content

Docker cli does not support defining port ranges in long form. #839

Open

Description

@estenrye

Description
docker cli does not support a method to publish a range of ports using the long form syntax.

Steps to reproduce the issue:

Describe the results you received:

PS D:\issue> docker run -p mode=host,target=9900-9999,published=9900-9999,protocol=tcp -d hello-world
C:\Program Files\Docker\Docker\Resources\bin\docker.exe: Invalid containerPort: mode=host,target=9900-9999,published=9900-9999,protocol=tcp.
See 'C:\Program Files\Docker\Docker\Resources\bin\docker.exe run --help'.

Describe the results you expected:

PS D:\issue> docker run -p mode=host,target=9900-9999,published=9900-9999,protocol=tcp -d hello-world
<ContainerId>

Impacts:

  • Customers with needs to define a large range of port bindings must declare each port individually if they need to use the long form syntax. This is burdensome and I would prefer to see parity between the long and short form syntax.

Output of docker version:

PS D:\issue> docker version
Client:
 Version:       17.12.0-ce
 API version:   1.35
 Go version:    go1.9.2
 Git commit:    c97c6d6
 Built: Wed Dec 27 20:05:22 2017
 OS/Arch:       windows/amd64

Server:
 Engine:
  Version:      17.12.0-ce
  API version:  1.35 (minimum version 1.24)
  Go version:   go1.9.2
  Git commit:   c97c6d6
  Built:        Wed Dec 27 20:15:52 2017
  OS/Arch:      windows/amd64
  Experimental: true

Output of docker info:

D:\issue> docker info
Containers: 2
 Running: 0
 Paused: 0
 Stopped: 2
Images: 148
Server Version: 17.12.0-ce
Storage Driver: windowsfilter
 Windows:
Logging Driver: json-file
Plugins:
 Volume: local
 Network: ics l2bridge l2tunnel nat null overlay transparent
 Log: awslogs etwlogs fluentd gelf json-file logentries splunk syslog
Swarm: inactive
Default Isolation: hyperv
Kernel Version: 10.0 15063 (15063.0.amd64fre.rs2_release.170317-1834)
Operating System: Windows 10 Pro
OSType: windows
Architecture: x86_64
CPUs: 24
Total Memory: 31.95GiB
Name: PMMP7-562
ID: 3NOE:IXLT:UD6I:BJXF:U3IE:UJIX:YUAO:HJZH:TLI2:ABHW:VB4K:BKB4
Docker Root Dir: D:\ProgramData\Docker
Debug Mode (client): false
Debug Mode (server): true
 File Descriptors: -1
 Goroutines: 25
 System Time: 2018-01-26T12:02:47.4595705-06:00
 EventsListeners: 1
Registry: https://index.docker.io/v1/
Labels:
Experimental: true
Insecure Registries:
 127.0.0.0/8
Live Restore Enabled: false

Related Issues:

Activity

  1. thaJeztah commented on May 22, 2018

    @thaJeztah
    Member

    Also related; #1074

  2. thaJeztah commented on May 22, 2018

    @thaJeztah
    Member

    I agree that this should be supported; If we want to accept port-ranges to be passed as well in the long form, we could either go for a "strict" approach;

    --publish publish-start=8080,publish-end=8090,target-start=80,target-end=90
    

    Or use the existing "range" notation:

    --publish publish=8080-8090,target=80-90
    

    I think the first option is too verbose, and will be cumbersome to use. While I think we should should generally avoid using "microformats" in options (as they can be ambiguous; causing more issues than they resolve), in this case, I think the "range" notation is well-defined, and ok to use.

    • We should probably not go beyond just ranges, i.e. we should not support formats such as: publish=8080-8090,8095,8097, because commas are already used as separator between values, and using them as part of a value will be hard to read, and can easily lead to confusion.
    • Similar to how the short-hand (-p 8080-8081:80-81) notation, this should be a client-side change; the given port-ranges are parsed in the CLI, and sent as individual ports through the API; so from an API perspective, -p 8080-8081:80-81 is the exact equivalent of -p 8080:80 -p 8081:81
  3. estenrye commented on May 23, 2018

    @estenrye
    Author

    @thaJeztah I think I like the shorter more terse syntax of the existing range notation.

    I agree that you probably shouldn't support disjointed ranges publish=8080-8090,8095,8097 for the reasons you have already stated and the fact that a user could implement a disjointed range by using multiple --publish arguments like so:

    --publish publish=8080-8090,target=80-90 --publish publish=8095,target=95 --publish publish=8097,target=97
    
  4. hogmoru commented on Jun 8, 2019

    @hogmoru

    Hmm, this works for me on Linux with 18.09.5, and 19.09.0-dev (built from current sources). It fails with 18.03-0-ce.

    Ran a few tests with various versions, looks like this is fixed since #1102 was merged... Or have I missed something?

    % docker run --publish mode=host,target=8080-8090,published=80-90,protocol=tcp -d hello-world
    11ce45b737477398f99eeba67fde05f946c1d6fcefd7fe7fa29082554739b870
    
    % docker version
    Client:
     Version:           18.09.5
     API version:       1.39
     Go version:        go1.10.4
     Git commit:        e8ff056
     Built:             Thu May  9 23:08:41 2019
     OS/Arch:           linux/amd64
     Experimental:      false
    
    Server:
     Engine:
      Version:          18.09.5
      API version:      1.39 (minimum version 1.12)
      Go version:       go1.10.4
      Git commit:       e8ff056
      Built:            Thu May  9 23:01:16 2019
      OS/Arch:          linux/amd64
      Experimental:     false
    
  5. jerradpatch commented on Jun 12, 2020

    @jerradpatch

    If it is fixed it could use some updates in the docs. I wanted this option and landed here while searching for it.

  6. 0x0elliot commented on Nov 22, 2022

    @0x0elliot

    this works as far as i know. shouldn't this be closed now?

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions