Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,7 @@ public HostConfig withMemorySwappiness(Long memorySwappiness) {
* <li>'host': use the host network stack inside the container. Note: the host mode gives the container full access to local system
* services such as D-bus and is therefore considered insecure.</li>
* </ul>
* Any other value is interpreted as a custom network's name for this container to connect to.
*/
public HostConfig withNetworkMode(String networkMode) {
this.networkMode = networkMode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ public CreateContainerResponse exec() throws NotFoundException, ConflictExceptio
containerNetwork.withAliases(aliases);
}

if (containerNetwork != null) {
if (containerNetwork != null && hostConfig.getNetworkMode() != null) {
networkingConfig = new NetworkingConfig()
.withEndpointsConfig(singletonMap(hostConfig.getNetworkMode(), containerNetwork));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exception was being thrown as we were putting:

EndpointsConfig: {
    null: containerNetwork
}

as networkMode is null by default. This can't be serialised by JSON so it throws.

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.github.dockerjava.api.model.Link;
import com.github.dockerjava.api.model.LogConfig;
import com.github.dockerjava.api.model.Network;
import com.github.dockerjava.api.model.PortBinding;
import com.github.dockerjava.api.model.Ports;
import com.github.dockerjava.api.model.Ports.Binding;
import com.github.dockerjava.api.model.RestartPolicy;
Expand Down Expand Up @@ -1125,4 +1126,15 @@ public void shouldNotEncodeAuth() {

assertThat(jsonNode.get("authConfig"), nullValue());
}

@Test
public void shouldHandleANetworkAliasWithoutACustomNetworkGracefully() {
// Should not throw
dockerRule.getClient()
.createContainerCmd(DEFAULT_IMAGE)
.withAliases("hello-world")
.withHostConfig(newHostConfig())
.withCmd("sleep", "9999")
.exec();
}
}