}
}
protected void startDockerContainer(String id, CreateDockerContainerOptions options) {
if (!Strings.isNullOrBlank(id)) {
HostConfig hostConfig = new HostConfig();
Map<String, Integer> externalPorts = options.getExternalPorts();
Map<String, Integer> internalPorts = options.getInternalPorts();
SortedMap<Integer, List<Map<String, String>>> sortedPortsToBinding = new TreeMap<>();
for (Map.Entry<String, Integer> entry : internalPorts.entrySet()) {
String portName = entry.getKey();
Integer internalPort = entry.getValue();
Integer externalPort = externalPorts.get(portName);
if (internalPort != null && externalPort != null) {
sortedPortsToBinding.put(internalPort, createNewPortConfig(externalPort));
}
}
// now lets add the bindings in port order
Map<String, List<Map<String, String>>> portBindings = new LinkedHashMap<>();
for (Map.Entry<Integer, List<Map<String, String>>> entry : sortedPortsToBinding.entrySet()) {
Integer internalPort = entry.getKey();
List<Map<String, String>> value = entry.getValue();
portBindings.put("" + internalPort + "/tcp", value);
}
hostConfig.setPortBindings(portBindings);
LOG.info("starting container " + id + " with " + hostConfig);
try {
docker.containerStart(id, hostConfig);
} catch (Exception e) {
LOG.error("Failed to start container " + id + " with " + hostConfig + " " + e + Dockers.dockerErrorMessage(e), e);