gradle-docker
gradle-docker copied to clipboard
Port of 0 is not allowed but is valid to docker
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)
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.
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.
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.
Thanks! :-)
The linked PR was closed as stale - has there been any other solution to this?