本文整理匯總了Java中com.spotify.docker.client.messages.AttachedNetwork類的典型用法代碼示例。如果您正苦於以下問題:Java AttachedNetwork類的具體用法?Java AttachedNetwork怎麽用?Java AttachedNetwork使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
AttachedNetwork類屬於com.spotify.docker.client.messages包,在下文中一共展示了AttachedNetwork類的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: isHostNet
import com.spotify.docker.client.messages.AttachedNetwork; //導入依賴的package包/類
/**
* 容器網絡模式是否為host模式
* @param containerId
* @return
*/
public static boolean isHostNet(String containerId){
String cacheKey = "isHostNet" + containerId;
Boolean v = (Boolean) getCache(cacheKey);
if (v != null){
return v;
}
Boolean value = false;
try {
ContainerInfo containerInfo = getContainerInfo(containerId);
if (containerInfo != null) {
ImmutableMap<String, AttachedNetwork> networks = containerInfo.networkSettings().networks();
if (networks != null && !networks.isEmpty()){
value = networks.get("host") != null && StringUtils.isNotEmpty(networks.get("host").ipAddress());
setCache(cacheKey,value);
}else {
log.warn("容器{}無Networks配置",containerInfo.name());
}
}
} catch (Exception e) {
log.error("",e);
}
return value;
}
示例2: getContainerIp
import com.spotify.docker.client.messages.AttachedNetwork; //導入依賴的package包/類
/**
* 獲取容器IP地址
* @param containerId
* 容器ID
* @return
* 1、獲取失敗返回null
* 2、host網絡模式直接返回宿主機IP
*/
public static String getContainerIp(String containerId){
String cacheKey = "containerIp" + containerId;
String v = (String) getCache(cacheKey);
if (StringUtils.isNotEmpty(v)) {
return v;
}
try {
if (isHostNet(containerId)){
return HostUtil.getHostIp();
}
ContainerInfo containerInfo = getContainerInfo(containerId);
if (containerInfo != null) {
ImmutableMap<String, AttachedNetwork> networks = containerInfo.networkSettings().networks();
if (networks != null && !networks.isEmpty()){
String ip = networks.get(networks.keySet().asList().get(0)).ipAddress();
setCache(cacheKey,ip);
return ip;
}else {
log.warn("容器{}無Networks配置",containerInfo.name());
}
}
} catch (Exception e) {
log.error("",e);
}
return null;
}