gradle-docker icon indicating copy to clipboard operation
gradle-docker copied to clipboard

Port of 0 is not allowed but is valid to docker

Open molexx opened this issue 6 years ago • 5 comments

If a port of 0 is passed in the mappings then docker allocates a free port, but trying to use 0 in dockerRun results in error 'Port must be in the range [1,65536]'.

(As an aside, this: https://stackoverflow.com/questions/42482278/bash-command-to-return-a-free-port suggests how to find which port has been allocated)

molexx avatar Mar 28 '18 16:03 molexx

If you want a dynamically assigned host port, you can just omit the host port from the port mapping. The second example in the answer of the post you linked to shows how to do this.

Omitting the host port is the more canonical way to get a dynamic host port. That behavior is fully supported by this plugin so I don't think there is any need for us to support specifying a port of 0.

pkoenig10 avatar Mar 30 '18 20:03 pkoenig10

It's difficult to configure if the calling script is parameterized so sometimes the port number is specified and sometimes it is not. An empty value followed by the colon then port number (e.g. :8080) fails as it tries to parse a number before the colon.

molexx avatar Apr 03 '18 11:04 molexx

I was actually incorrect in my statement above, this plugin does not allocate a dynamic port when the host port is omitted. Instead it just uses the specified container port as the host port. This is unfortunate because it does not match the behavior of docker run making the usage here a bit confusing.

In that case, I think supporting port 0 for the host is valuable.

pkoenig10 avatar Apr 10 '18 04:04 pkoenig10

Thanks! :-)

molexx avatar Apr 10 '18 12:04 molexx

The linked PR was closed as stale - has there been any other solution to this?

madrob avatar Jul 14 '20 15:07 madrob