Allow multiple port bindings per ExposedPort by albers · Pull Request #82 · docker-java/docker-java

docker-java currently maps the Docker API elements .HostConfig.PortBindings and .NetworkSettings.Ports to a Map<ExposedPort, Binding>. This is incorrect. There may be multiple Bindings per ExposedPort. The API element is an array.

To illustrate, create a container with docker run -d -p 80:80 -p 81:80 eboraas/apache:latest. Docker remote API will report

"PortBindings":{"80/tcp":[{"HostIp":"","HostPort":"80"},{"HostIp":"","HostPort":"81"}]}
"Ports":{"443/tcp":null,"80/tcp":[{"HostIp":"0.0.0.0","HostPort":"80"},{"HostIp":"0.0.0.0","HostPort":"81"}]}}

docker-java will only give you access to the first Binding, as shown by the test contributed in d1f31cd. There is no way to create multiple port bindings per ExposedPort with the current state of docker-java.

This PR changes the type used for storing port bindings to Map<ExposedPort, Binding[]>, solving both problems.