Skip to content
This repository has been archived by the owner on Jun 22, 2018. It is now read-only.

Commit

Permalink
Merge pull request #418 from ContainerSolutions/bug/network-gateway
Browse files Browse the repository at this point in the history
Network gateway is now determined using Master container ID
  • Loading branch information
sadovnikov committed May 2, 2016
2 parents 9115c72 + 01ef2d4 commit a32e23c
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -235,13 +235,8 @@ public void onComplete() {
/**
* @return IP Address of the container's gateway (which would be docker0)
*/
public static String getGatewayIpAddress() {
List<Container> containers = DockerClientFactory.build().listContainersCmd().exec();
if (containers == null || containers.size() == 0) {
throw new IllegalStateException("Cannot get docker0 IP address because no containers are running");
}

InspectContainerResponse response = DockerClientFactory.build().inspectContainerCmd(containers.get(0).getId()).exec();
public static String getGatewayIpAddress(String containerId) {
InspectContainerResponse response = DockerClientFactory.build().inspectContainerCmd(containerId).exec();
return response.getNetworkSettings().getGateway();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public String replaceTokens(String source) {
}

// replace independent from roles tokens
updatedJson = replaceToken(updatedJson, TOKEN_NETWORK_GATEWAY, DockerContainersUtil.getGatewayIpAddress());
updatedJson = replaceToken(updatedJson, TOKEN_NETWORK_GATEWAY, DockerContainersUtil.getGatewayIpAddress(getCluster().getMaster().getContainerId()));

return updatedJson;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ protected CreateContainerCmd dockerCommand() {
portBindings.bind(consulHTTPPort, new Ports.Binding(ConsulConfig.CONSUL_HTTP_PORT));
}


String gatewayIpAddress = DockerContainersUtil.getGatewayIpAddress();
String gatewayIpAddress = DockerContainersUtil.getGatewayIpAddress(getCluster().getMaster().getContainerId());
portBindings.bind(consulDNSPort, new Ports.Binding(gatewayIpAddress, DNS_PORT));

return DockerClientFactory.build().createContainerCmd(config.getImageName() + ":" + config.getImageTag())
Expand Down

0 comments on commit a32e23c

Please sign in to comment.