X Tutup
Skip to content

Improve adding of port bindings#87

Merged
marcuslinke merged 4 commits intodocker-java:masterfrom
albers:port-binding
Nov 5, 2014
Merged

Improve adding of port bindings#87
marcuslinke merged 4 commits intodocker-java:masterfrom
albers:port-binding

Conversation

@albers
Copy link
Copy Markdown
Contributor

@albers albers commented Oct 31, 2014

Adding port bindings involves the creation of a Ports object that has a confusing notion of bindings: in order to add a port binding, you Ports.bind a Binding and hand it over to withPortBinding.

Other builder methods offer more intuitive idioms that directly correspond to Docker CLI options, e.g. withBinds(Bind...) and withLinks(Link...).

With this PR, you can do things like

StartContainerCmd.withPortBindings( PortBinding.parse("80:8080/tcp"),
new PortBinding(Ports.Binding(90), ExposedPort.tcp(9090) ) );

The old way of working with Ports still exists. Querying port bindings from an InspectContainerResponse was not changed.

See individual commit messages for details.

The use of Ports for adding port bindings requires knowledge of the
internal data structure used for storing port bindings in Docker API.

This commit adds a more intuitive alternative that works like the
--publish option of the Docker CLI and some builder methods like
withBinds(Bind...) and withLinks(Link...).
This allows you to use textual port binding specifications in the format
used by the Docker CLI in docker-java:

StartContainerCmd.withPortBindings(PortBinding.parse("80:8080/tcp"));
In Docker API, an undefined IP address is expressed as "".
This is not intuitive and should be hidden from the user.
Likewise, docker-java uses 0 for an unspecified port number.
This also is not intuitive, especially if you consider that 0 is a legal
port number.

This change makes the undefinedness explicit by using null in both
cases. When serializing, "" is used instead of null.
This implies changing the type of hostPort from int to Integer.
albers added a commit to albers/docker-build-step-plugin that referenced this pull request Nov 4, 2014
marcuslinke added a commit that referenced this pull request Nov 5, 2014
Improve adding of port bindings
@marcuslinke marcuslinke merged commit ac83789 into docker-java:master Nov 5, 2014
@marcuslinke
Copy link
Copy Markdown
Contributor

@albers Thanks!

@albers albers deleted the port-binding branch November 5, 2014 08:31
albers added a commit to albers/docker-build-step-plugin that referenced this pull request Nov 5, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

X Tutup