.withEndpointsConfig(singletonMap(hostConfig.getNetworkMode(), containerNetwork));
public ContainerAssert hasNetworkMode(String networkMode) { isNotNull(); if (getHostConfig() != null && !Objects.areEqual(getHostConfig().getNetworkMode(), networkMode)) { failWithMessage("Expected container's networkMode to be %s but was %s", networkMode, getHostConfig().getNetworkMode()); } return this; }
/** * compares if microservice has root host access, then container will have the NetworkMode 'host', * otherwise container has to have ExtraHosts * * @param inspectInfo result of docker inspect command * @param microservice microservice * @return boolean */ private boolean isNetworkModeEqual(InspectContainerResponse inspectInfo, Microservice microservice) { boolean isRootHostAccess = microservice.isRootHostAccess(); HostConfig hostConfig = inspectInfo.getHostConfig(); return (isRootHostAccess && "host".equals(hostConfig.getNetworkMode())) || !isRootHostAccess && (hostConfig.getExtraHosts() != null && hostConfig.getExtraHosts().length > 0); }
void setNetworkMode(Instance instance, ContainerConfig containerConfig, HostConfig hostConfig) { if(DataAccessor.fields(instance).withKey(FIELD_NETWORK_MODE).get() != null) return; String netMode = null; if (containerConfig != null && containerConfig.isNetworkDisabled()) { netMode = NetworkConstants.NETWORK_MODE_NONE; } else if (hostConfig != null) { String inspectNetMode = hostConfig.getNetworkMode(); if (NetworkConstants.NETWORK_MODE_BRIDGE.equals(inspectNetMode) || NetworkConstants.NETWORK_MODE_HOST.equals(inspectNetMode) || NetworkConstants.NETWORK_MODE_NONE.equals(inspectNetMode)) { netMode = inspectNetMode; } else if (NetworkConstants.NETWORK_MODE_DEFAULT.equals(inspectNetMode) || StringUtils.isBlank(inspectNetMode)) { netMode = NetworkConstants.NETWORK_MODE_BRIDGE; } else if (StringUtils.startsWith(inspectNetMode, NetworkConstants.NETWORK_MODE_CONTAINER)) { throw new ClientVisibleException(ResponseCodes.UNPROCESSABLE_ENTITY, ValidationErrorCodes.INVALID_OPTION, "Transformer API does not support container network mode.", null); } else { throw new ClientVisibleException(ResponseCodes.UNPROCESSABLE_ENTITY, ValidationErrorCodes.INVALID_OPTION, "Unrecognized network mode: " + inspectNetMode, null); } } setField(instance, FIELD_NETWORK_MODE, netMode); }
} else { InspectContainerResponse inspect = executor.inspectContainer(containerId); final String defaultNetwork = inspect.getHostConfig().getNetworkMode(); nwList.add(defaultNetwork);
.withEndpointsConfig(singletonMap(hostConfig.getNetworkMode(), containerNetwork));