本文整理汇总了Java中com.github.dockerjava.api.command.CreateContainerCmd.withNetworkMode方法的典型用法代码示例。如果您正苦于以下问题:Java CreateContainerCmd.withNetworkMode方法的具体用法?Java CreateContainerCmd.withNetworkMode怎么用?Java CreateContainerCmd.withNetworkMode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.github.dockerjava.api.command.CreateContainerCmd
的用法示例。
在下文中一共展示了CreateContainerCmd.withNetworkMode方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run
import com.github.dockerjava.api.command.CreateContainerCmd; //导入方法依赖的package包/类
@Override
protected String run() throws Exception {
CreateContainerCmd createCmd = dockerClient.createContainerCmd(imageId);
createCmd.withAttachStderr(true).withAttachStdout(true).withName(params.getName());
createCmd.withNetworkMode(bridgeNetworkName.toString());
if (!params.getBinds().isEmpty()) {
createCmd.withBinds(createBinds());
}
if (params.getPortBinds().isEmpty()) {
createCmd.withPublishAllPorts(true);
} else {
createCmd.withExposedPorts(createExposedPorts()).withPortBindings(createPorts());
}
if (params.getCommand().isPresent()) {
createCmd.withCmd(params.getCommand().get());
}
if (!params.getEnvs().isEmpty()) {
String[] envs = params.getEnvs().stream().map(env -> String.format("%s='%s'", env.getName(), env.getValue().get())).toArray(String[]::new);
createCmd.withEnv(envs);
}
try {
return createCmd.exec().getId();
} finally {
createCmd.close();
}
}
示例2: run
import com.github.dockerjava.api.command.CreateContainerCmd; //导入方法依赖的package包/类
@Override
public List<String> run(TestEnvironment testEnvironment) {
String hostOsMountDir = System.getProperties().getProperty("buildDirectory");
CreateContainerCmd containerBuilder = dockerClient.createContainerCmd(testEnvironment.getImage())
.withBinds(new Bind(hostOsMountDir, new Volume(Constants.HAWKULAR_APM_AGENT_DIRECTORY),
AccessMode.ro, SELContext.shared),
new Bind(scenarioDirectory, new Volume(Constants.HAWKULAR_APM_TEST_DIRECTORY),
AccessMode.ro, SELContext.shared))
.withExtraHosts(Constants.HOST_ADDED_TO_ETC_HOSTS + ":" + apmBindAddress);
if (userDefinedNetwork) {
if (network == null) {
throw new IllegalStateException("Create network before running environment");
}
containerBuilder.withNetworkMode(network.getName());
}
containerBuilder.withEnv(apmEnvVariables(testEnvironment.getType()));
if (testEnvironment.isPull()) {
log.info("Pulling image...");
dockerClient.pullImageCmd(testEnvironment.getImage()).exec(new PullImageResultCallback()).awaitSuccess();
}
CreateContainerResponse containerResponse = containerBuilder.exec();
log.info(String.format("Starting docker container: %s", containerResponse));
try {
dockerClient.startContainerCmd(containerResponse.getId()).exec();
} catch (DockerException ex) {
log.severe(String.format("Could not create or start docker container: %s", containerResponse));
throw new EnvironmentException("Could not create or start docker container.", ex);
}
return Arrays.asList(containerResponse.getId());
}
示例3: startNode
import com.github.dockerjava.api.command.CreateContainerCmd; //导入方法依赖的package包/类
public void startNode(String id, BrowserType browserType, String nodeName, String imageId,
String hubIp, String containerIp) {
// Create node if not exist
if (!existsContainer(nodeName)) {
pullImageIfNecessary(imageId, false);
log.debug("Creating container {}", nodeName);
CreateContainerCmd createContainerCmd =
getClient().createContainerCmd(imageId).withName(nodeName);
createContainerCmd.withNetworkMode("none");
Map<String, String> labels = new HashMap<>();
labels.put("KurentoDnat", "true");
labels.put("Transport", getProperty(TEST_SELENIUM_TRANSPORT));
labels.put("IpAddress", containerIp);
createContainerCmd.withLabels(labels);
createContainerCmd.withEnv(new String[] { "HUB_PORT_4444_TCP_ADDR=" + hubIp,
"SE_OPTS=\"-host " + containerIp + " -port 5555\"" });
createContainerCmd.exec();
log.debug("Container {} started...", nodeName);
} else {
log.debug("Container {} already exists", nodeName);
}
// Start node if stopped
startContainer(nodeName);
}