compose: Docker Compose does not support defining port ranges in long form.
Issue
docker-compose file format does not support a method of declaring port ranges in the long form syntax defined here: https://docs.docker.com/compose/compose-file/#long-syntax-1
Steps to Reproduce
docker-compose.yml:
version: '3.4'
services:
helloWorld:
image: hello-world
ports:
- target: 9900-9999
published: 9900-9999
protocol: tcp
mode: host
command executed:
docker-compose -f ./docker-compose.yml config
docker-comopse -f ./docker-compose.yml up -d
Expected Output:
PS D:\issue> docker-compose -f ./docker-compose.yml config
services:
helloWorld:
image: hello-world
ports:
- target: 9900-9999
published: 9900-9999
protocol: tcp
mode: host
version: '3.4'
PS D:\issue> docker-compose -f ./docker-compose.yml up -d
<ContainerId>
Actual Output:
PS D:\issue> docker-compose -f ./docker-compose.yml config
Traceback (most recent call last):
File "docker-compose", line 6, in <module>
File "compose\cli\main.py", line 71, in main
File "compose\cli\main.py", line 118, in perform_command
File "compose\cli\main.py", line 304, in config
File "compose\cli\command.py", line 47, in get_config_from_options
File "compose\config\config.py", line 375, in load
File "compose\config\config.py", line 506, in process_config_file
File "compose\config\config.py", line 497, in interpolate_config_section
File "compose\config\interpolation.py", line 44, in interpolate_environment_variables
File "compose\config\interpolation.py", line 44, in <genexpr>
File "compose\config\interpolation.py", line 39, in process_item
File "compose\config\interpolation.py", line 39, in <genexpr>
File "compose\config\interpolation.py", line 54, in interpolate_value
File "compose\config\interpolation.py", line 77, in recursive_interpolate
File "compose\config\interpolation.py", line 74, in recursive_interpolate
File "compose\config\interpolation.py", line 74, in <genexpr>
File "compose\config\interpolation.py", line 70, in recursive_interpolate
File "compose\config\interpolation.py", line 184, in convert
File "compose\config\interpolation.py", line 141, in to_int
ValueError: invalid literal for int() with base 0: '9900-9999'
Failed to execute script docker-compose
PS D:\issue> docker-compose -f ./docker-compose.yml up -d
Traceback (most recent call last):
File "docker-compose", line 6, in <module>
File "compose\cli\main.py", line 71, in main
File "compose\cli\main.py", line 121, in perform_command
File "compose\cli\command.py", line 37, in project_from_options
File "compose\cli\command.py", line 91, in get_project
File "compose\config\config.py", line 375, in load
File "compose\config\config.py", line 506, in process_config_file
File "compose\config\config.py", line 497, in interpolate_config_section
File "compose\config\interpolation.py", line 44, in interpolate_environment_variables
File "compose\config\interpolation.py", line 44, in <genexpr>
File "compose\config\interpolation.py", line 39, in process_item
File "compose\config\interpolation.py", line 39, in <genexpr>
File "compose\config\interpolation.py", line 54, in interpolate_value
File "compose\config\interpolation.py", line 77, in recursive_interpolate
File "compose\config\interpolation.py", line 74, in recursive_interpolate
File "compose\config\interpolation.py", line 74, in <genexpr>
File "compose\config\interpolation.py", line 70, in recursive_interpolate
File "compose\config\interpolation.py", line 184, in convert
File "compose\config\interpolation.py", line 141, in to_int
ValueError: invalid literal for int() with base 0: '9900-9999'
Failed to execute script docker-compose
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
Docker-Compose Version
D:\issue> docker-compose version
docker-compose version 1.18.0, build 8dd22a96
docker-py version: 2.6.1
CPython version: 2.7.14
OpenSSL version: OpenSSL 1.0.2k 26 Jan 2017
Observations
- docker-compose only accepts a single port in long form syntax.
- docker currently appears to only support a single port in long form syntax. See https://github.com/moby/moby/issues/32551
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'.
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.
Workaround
- Customers who do not need to use the long form syntax can use the short form syntax to declare a range of ports.
- Customers who must use the long form syntax, to control which protocol is used or to bind the ports on the ingress network when deploying to swarm, need to declare each port individually in their compose files.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 26
- Comments: 41
thanks, stale-bot, im sure its just gone and resolved itself. not.
This issue has been 2 years old and it is very neccessary for popular services that open range of UDP ports to comminicate like RTP protocol. Any one has a way to by pass this issue?
I also ran into this issue today and wold love to see it resolved!
Just commenting so Stale bot doesn’t mark this as stale.
On a serious note, would love to see this resolved.
This comment https://github.com/docker/cli/issues/839#issuecomment-500136821 seems to say that the problem is solved on the docker-cli side. The logical next step would be for compose to follow.
@koyukan if you use network-mode = host then your container will be created without any network abstraction, and port mapping is not supported. So basically, all port exposed by container are just exposed as-is on host without the need for any additional configuration.
This has been (partially) fixed on the Compose-specification: https://github.com/compose-spec/compose-spec/pull/222 now need to get this also implemented in the code
+1
@koyukan why don’t you use the short syntax for this purpose ?
+1
came here with hopium, left here with a compose file larger than life…
No updated on this yet? Encountered this problem as well.
Still nothing?