本文整理汇总了Java中com.github.dockerjava.api.command.CreateContainerResponse.getId方法的典型用法代码示例。如果您正苦于以下问题:Java CreateContainerResponse.getId方法的具体用法?Java CreateContainerResponse.getId怎么用?Java CreateContainerResponse.getId使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.github.dockerjava.api.command.CreateContainerResponse
的用法示例。
在下文中一共展示了CreateContainerResponse.getId方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createContainer
import com.github.dockerjava.api.command.CreateContainerResponse; //导入方法依赖的package包/类
private String createContainer(){
ensureImage(imageName);
CreateContainerCmd createContainerCmd = dockerClient
.createContainerCmd(containerName)
.withImage(imageName)
.withCmd("sleep", "9999")
.withLabels(label(containerName))
.withName(containerName);
if(bindings != null){
createContainerCmd.withBinds(bindings);
}
CreateContainerResponse resp = createContainerCmd.exec();
return resp.getId();
}
示例2: createContainerWithNetworkID
import com.github.dockerjava.api.command.CreateContainerResponse; //导入方法依赖的package包/类
@Test
public void createContainerWithNetworkID() {
assumeThat("API version should be >= 1.23", dockerRule, isGreaterOrEqual(VERSION_1_24));
String networkName = "net-" + UUID.randomUUID().toString();
Map<String, String> labels = new HashMap<>();
labels.put("com.example.label", "test");
CreateNetworkResponse createNetworkResponse = dockerRule.getClient().createNetworkCmd().withName(networkName)
.withLabels(labels).withAttachable(true).exec();
String networkId = createNetworkResponse.getId();
CreateContainerResponse createContainerResponse = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE).withLabels(labels).withCmd("true").exec();
String containerId = createContainerResponse.getId();
dockerRule.getClient().connectToNetworkCmd().withContainerId(containerId).withNetworkId(networkId).exec();
InspectContainerResponse inspectContainerResponse = dockerRule.getClient().inspectContainerCmd(containerId).exec();
ContainerNetwork containerNetwork = inspectContainerResponse.getNetworkSettings().getNetworks().get(networkName);
if (containerNetwork == null) {
// swarm node used network id
containerNetwork = inspectContainerResponse.getNetworkSettings().getNetworks().get(networkId);
}
assertThat(containerNetwork, notNullValue());
}
示例3: runContainer
import com.github.dockerjava.api.command.CreateContainerResponse; //导入方法依赖的package包/类
/**
* for publishers/builders. Simply runs container in docker cloud
*/
public static String runContainer(DockerTemplateBase dockerTemplateBase,
DockerClient dockerClient) {
CreateContainerCmd containerConfig = dockerClient.createContainerCmd(dockerTemplateBase.getImage());
dockerTemplateBase.fillContainerConfig(containerConfig);
// create
CreateContainerResponse response = containerConfig.exec();
String containerId = response.getId();
// start
StartContainerCmd startCommand = dockerClient.startContainerCmd(containerId);
startCommand.exec();
return containerId;
}
示例4: startContainer
import com.github.dockerjava.api.command.CreateContainerResponse; //导入方法依赖的package包/类
private String startContainer(CreateContainerCmd cmd, DockerClient client) {
CreateContainerResponse createResp = cmd.exec();
StartContainerCmd startCmd = client.startContainerCmd(createResp.getId());
try {
startCmd.exec();
} catch (Throwable t) {
throw new ContainerException(createResp.getId(), t);
}
return startCmd.getContainerId();
}
示例5: initTestContainer
import com.github.dockerjava.api.command.CreateContainerResponse; //导入方法依赖的package包/类
protected void initTestContainer()
throws Exception {
final String scenarioFileName = scenarioPath.getFileName().toString();
int dotPos = scenarioFileName.lastIndexOf('.');
if(dotPos > 0) {
final String scenarioFileExt = scenarioFileName.substring(dotPos + 1);
final String dockerImageName = SCENARIO_LANG_IMAGES.get(scenarioFileExt);
if(dockerImageName == null) {
fail();
}
System.out.println("docker pull " + dockerImageName + "...");
dockerClient.pullImageCmd(dockerImageName)
.exec(new PullImageResultCallback())
.awaitSuccess();
final List<String> cmd = new ArrayList<>();
cmd.add("-Xms1g");
cmd.add("-Xmx1g");
cmd.add("-XX:MaxDirectMemorySize=1g");
cmd.add("-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005");
cmd.add("-Dcom.sun.management.jmxremote=true");
cmd.add("-Dcom.sun.management.jmxremote.port=9010");
cmd.add("-Dcom.sun.management.jmxremote.rmi.port=9010");
cmd.add("-Dcom.sun.management.jmxremote.local.only=false");
cmd.add("-Dcom.sun.management.jmxremote.authenticate=false");
cmd.add("-Dcom.sun.management.jmxremote.ssl=false");
cmd.add("-jar");
cmd.add("/opt/mongoose/mongoose.jar");
cmd.addAll(configArgs);
final StringJoiner cmdLine = new StringJoiner(" ");
cmd.forEach(cmdLine::add);
System.out.println("Container arguments: " + cmdLine.toString());
final Volume volumeShare = new Volume(CONTAINER_SHARE_PATH);
final Volume volumeLog = new Volume(CONTAINER_LOG_PATH);
final Bind[] binds = new Bind[] {
new Bind(HOST_SHARE_PATH.toString(), volumeShare),
new Bind(HOST_LOG_PATH.toString(), volumeLog),
};
// put the environment variables into the container
final Map<String, String> envMap = System.getenv();
final String[] env = envMap.keySet().toArray(new String[envMap.size()]);
for(int i = 0; i < env.length; i ++) {
if("PATH".equals(env[i])) {
env[i] = env[i] + "=" + envMap.get(env[i]) + ":/bin";
} else {
env[i] = env[i] + "=" + envMap.get(env[i]);
}
}
final CreateContainerResponse container = dockerClient
.createContainerCmd(dockerImageName)
.withName("mongoose")
.withNetworkMode("host")
.withExposedPorts(ExposedPort.tcp(9010), ExposedPort.tcp(5005))
.withVolumes(volumeShare, volumeLog)
.withBinds(binds)
.withAttachStdout(true)
.withAttachStderr(true)
.withEnv(env)
.withEntrypoint("mongoose")
.withCmd(cmd)
.exec();
testContainerId = container.getId();
dockerClient
.attachContainerCmd(testContainerId)
.withStdErr(true)
.withStdOut(true)
.withFollowStream(true)
.exec(streamsCallback);
} else {
fail();
}
}
示例6: create
import com.github.dockerjava.api.command.CreateContainerResponse; //导入方法依赖的package包/类
@Override
public String create(String image, String name, String[] env, String[] linking) {
DockerClient dockerClient = getClient();
if (image == null || image.trim().length() == 0) {
LOGGER.error("Container's image name to create is empty");
return null;
}
final CreateContainerCmd createContainerCmd = dockerClient.createContainerCmd(image)
.withPublishAllPorts(true)
.withAttachStdout(true)
.withAttachStdin(true)
.withAttachStdin(true)
.withTty(true);
if (linking != null) {
final String linkName = linking[0];
final String linkAlias = linking[1];
final Link link = new Link(linkName, linkAlias);
createContainerCmd.withLinks(link);
}
if (name != null && name.trim().length() > 0) createContainerCmd.withName(name);
if (env != null && env.length > 0) createContainerCmd.withEnv(env);
final CreateContainerResponse createContainerResponse = createContainerCmd.exec();
final String id = createContainerResponse.getId();
return id;
}
示例7: testExecutor
import com.github.dockerjava.api.command.CreateContainerResponse; //导入方法依赖的package包/类
@Test
public void testExecutor() throws MalformedURLException, UnsupportedEncodingException, InterruptedException {
DockerClient dockerClient = DockerUtil.buildDockerClient("https://192.168.99.100:2376", "/Users/vuminhkh/.docker/machine/machines/default/");
dockerClient.pullImageCmd("toscaruntime/ubuntu-trusty").exec(new PullImageResultCallback()).awaitCompletion();
CreateContainerResponse container = dockerClient.createContainerCmd("toscaruntime/ubuntu-trusty").withCmd("sleep", "9999")
.withName("test2").exec();
try {
dockerClient.startContainerCmd(container.getId()).exec();
DockerExecutor dockerExecutor = new DockerExecutor(dockerClient, container.getId(), false);
ExecutorService executorService = Executors.newCachedThreadPool();
dockerExecutor.upload("/Users/vuminhkh/Downloads/tdk-test/scripts/", "/tmp/");
executorService.submit(() -> {
Map<String, String> env = new HashMap<>();
dockerExecutor.executeArtifact("install java", Paths.get("/Users/vuminhkh/Downloads/tdk-test/scripts/Soft/create.sh"), "/tmp/Soft/create.sh", env);
});
// executorService.submit(() -> {
// Map<String, String> env = new HashMap<>();
// env.put("TOMCAT_HOME", "/opt/tomcat");
// env.put("TOMCAT_PORT", "80");
// env.put("TOMCAT_URL", "http://mirrors.ircam.fr/pub/apache/tomcat/tomcat-8/v8.0.33/bin/apache-tomcat-8.0.33.tar.gz");
// dockerExecutor.executeArtifact("install tomcat", Paths.get("/Users/vuminhkh/Projects/samples/tomcat-war/scripts/tomcat_install.sh"), "/tmp/tomcat_install.sh", env);
// });
executorService.shutdown();
executorService.awaitTermination(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
} finally {
dockerClient.removeContainerCmd(container.getId()).withForce(true).exec();
}
}
示例8: DockerContainer
import com.github.dockerjava.api.command.CreateContainerResponse; //导入方法依赖的package包/类
public DockerContainer(CreateContainerResponse containerCreateResponse,
InspectContainerResponse containerInspectResponse,
Image image) {
super(containerCreateResponse.getId(), image, containerInspectResponse.getState().isRunning());
this.containerCreateResponse = containerCreateResponse;
this.containerInspectResponse = containerInspectResponse;
fillPortMapping(containerInspectResponse);
}
示例9: createContainer
import com.github.dockerjava.api.command.CreateContainerResponse; //导入方法依赖的package包/类
/**
* Creates a Docker container object.
* @param imageName docker image container will be created from
* @param containerName container to be created
* @param command String array of usable commands
* @return container String id
*/
public String createContainer(String imageName, String containerName, String[] command) {
CreateContainerResponse container = dockerClient
.createContainerCmd(imageName).withCmd(command)
.withName(containerName).exec();
LOG.info("Created container {}", container.toString());
return container.getId();
}
示例10: testWithStopSignal
import com.github.dockerjava.api.command.CreateContainerResponse; //导入方法依赖的package包/类
/**
* https://github.com/calavera/docker/blob/3781cde61ff10b1d9114ae5b4c5c1d1b2c20a1ee/integration-cli/docker_cli_run_unix_test.go#L319-L333
*/
@Test
public void testWithStopSignal() throws Exception {
Integer signal = 10; // SIGUSR1 in busybox
CreateContainerResponse resp = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE)
.withCmd("/bin/sh", "-c", "trap 'echo \"exit trapped 10\"; exit 10' USR1; while true; do sleep 1; done")
.withAttachStdin(true)
.withTty(true)
.withStopSignal(signal.toString())
.exec();
final String containerId = resp.getId();
assertThat(containerId, not(isEmptyString()));
dockerRule.getClient().startContainerCmd(containerId).exec();
InspectContainerResponse inspect = dockerRule.getClient().inspectContainerCmd(containerId).exec();
assertThat(inspect.getState().getRunning(), is(true));
dockerRule.getClient().stopContainerCmd(containerId).exec();
Thread.sleep(TimeUnit.SECONDS.toMillis(3));
inspect = dockerRule.getClient().inspectContainerCmd(containerId).exec();
assertThat(inspect.getState().getRunning(), is(false));
assertThat(inspect.getState().getExitCode(), is(signal));
StringBuilder stringBuilder = new StringBuilder();
final StringBuilderLogReader callback = new StringBuilderLogReader(stringBuilder);
dockerRule.getClient().logContainerCmd(containerId)
.withStdErr(true)
.withStdOut(true)
.withTailAll()
.exec(callback)
.awaitCompletion();
String log = callback.builder.toString();
assertThat(log, is("exit trapped 10"));
}
示例11: createContainer
import com.github.dockerjava.api.command.CreateContainerResponse; //导入方法依赖的package包/类
public static ClosableContainer createContainer(DockerClient dockerClient, CreateContainerCmd createCmd) {
CreateContainerResponse commandResponse = createCmd.exec();
String containerId = commandResponse.getId();
return new ClosableContainer(dockerClient, containerId);
}
示例12: setUpDistributedModeIfNeeded
import com.github.dockerjava.api.command.CreateContainerResponse; //导入方法依赖的package包/类
private void setUpDistributedModeIfNeeded()
throws Exception {
final int n = driverCount.getValue();
if(n > 1) {
System.out.println("docker pull " + STORAGE_DRIVER_IMAGE_NAME + "...");
dockerClient.pullImageCmd(STORAGE_DRIVER_IMAGE_NAME)
.exec(new PullImageResultCallback())
.awaitCompletion();
storageDriverBuilderSvcs = new ArrayList<>(n);
final DriverConfig driverConfig = config.getStorageConfig().getDriverConfig();
final StringJoiner storageDriverAddrsOption = new StringJoiner(
",", "--storage-driver-addrs=", ""
);
int nextStorageDriverPort;
for(int i = 0; i < n; i ++) {
nextStorageDriverPort = driverConfig.getPort() + i;
final String[] cmd = {
"-Xms1g", "-Xmx1g", "-XX:MaxDirectMemorySize=1g",
"-jar", "/opt/mongoose/mongoose-storage-driver-service.jar",
"--storage-driver-port=" + nextStorageDriverPort
};
final CreateContainerResponse container = dockerClient
.createContainerCmd(STORAGE_DRIVER_IMAGE_NAME)
.withName("mongoose_storage_driver_service_" + nextStorageDriverPort)
.withNetworkMode("host")
.withExposedPorts(ExposedPort.tcp(nextStorageDriverPort))
.withEntrypoint("mongoose")
.withCmd(cmd)
.exec();
final String containerId = container.getId();
dockerClient.startContainerCmd(containerId).exec();
Loggers.TEST.info(
"Started the storage driver service @ port #{} in the container {}",
nextStorageDriverPort, containerId
);
storageDriverBuilderSvcs.add(containerId);
storageDriverAddrsOption.add("127.0.0.1:" + nextStorageDriverPort);
}
configArgs.add(storageDriverAddrsOption.toString());
configArgs.add("--storage-driver-remote");
}
}
示例13: createContainer
import com.github.dockerjava.api.command.CreateContainerResponse; //导入方法依赖的package包/类
/**
* creates {@link Container}
*
* @param element - {@link Element}
* @param host - host ip address
* @return id of created {@link Container}
* @throws Exception
*/
public String createContainer(Element element, String host) throws Exception {
RestartPolicy restartPolicy = RestartPolicy.onFailureRestart(10);
Ports portBindings = new Ports();
List<ExposedPort> exposedPorts = new ArrayList<>();
if (element.getPortMappings() != null)
element.getPortMappings().forEach(mapping -> {
ExposedPort internal = ExposedPort.tcp(Integer.parseInt(mapping.getInside()));
Ports.Binding external = Ports.Binding(Integer.parseInt(mapping.getOutside()));
portBindings.bind(internal, external);
exposedPorts.add(internal);
});
String[] extraHosts = { host };
Map<String, String> containerLogConfig = new HashMap<String, String>();
int logFiles = 1;
if (element.getLogSize() > 2)
logFiles = (int) (element.getLogSize() / 2);
containerLogConfig.put("max-file", String.valueOf(logFiles));
containerLogConfig.put("max-size", "2m");
LogConfig containerLog = new LogConfig(LogConfig.LoggingType.DEFAULT, containerLogConfig);
CreateContainerCmd cmd = dockerClient.createContainerCmd(element.getImageName())
.withLogConfig(containerLog)
.withCpuset("0")
.withExposedPorts(exposedPorts.toArray(new ExposedPort[0]))
.withPortBindings(portBindings)
.withEnv("SELFNAME=" + element.getElementId())
.withName(element.getElementId())
.withRestartPolicy(restartPolicy);
// if (element.getImageName().startsWith("iotracks/catalog:core-networking"))
// cmd = cmd.withMemoryLimit(256 * Constants.MiB);
if (StringUtil.isNullOrEmpty(host))
cmd = cmd.withNetworkMode("host").withPrivileged(true);
else
cmd = cmd.withExtraHosts(extraHosts);
CreateContainerResponse resp = cmd.exec();
return resp.getId();
}
示例14: updateContainer
import com.github.dockerjava.api.command.CreateContainerResponse; //导入方法依赖的package包/类
@Test
public void updateContainer() throws DockerException, IOException {
assumeThat("API version should be >= 1.22", dockerRule, isGreaterOrEqual(VERSION_1_22));
CreateContainerResponse response = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE)
.withCmd("sleep", "9999")
.exec();
String containerId = response.getId();
dockerRule.getClient().startContainerCmd(containerId).exec();
InspectContainerResponse inspectBefore = dockerRule.getClient().inspectContainerCmd(containerId).exec();
LOG.debug("Inspect: {}", inspectBefore);
final Long memory = inspectBefore.getHostConfig().getMemory();
final UpdateContainerResponse updateResponse = dockerRule.getClient().updateContainerCmd(containerId)
.withBlkioWeight(300)
.withCpuShares(512)
.withCpuPeriod(100000)
.withCpuQuota(50000)
// .withCpusetCpus("0") // depends on env
.withCpusetMems("0")
// .withMemory(209715200L + 2L)
// .withMemorySwap(514288000L) Your kernel does not support swap limit capabilities, memory limited without swap.
// .withMemoryReservation(209715200L)
// .withKernelMemory(52428800) Can not update kernel memory to a running container, please stop it first.
.exec();
// true only on docker toolbox (1.10.1)
// assertThat(updateResponse.getWarnings(), hasSize(1));
// assertThat(updateResponse.getWarnings().get(0),
// is("Your kernel does not support Block I/O weight. Weight discarded."));
InspectContainerResponse inspectAfter = dockerRule.getClient().inspectContainerCmd(containerId).exec();
final HostConfig afterHostConfig = inspectAfter.getHostConfig();
// assertThat(afterHostConfig.getMemory(), is(209715200L + 2L));
// assertThat(afterHostConfig.getBlkioWeight(), is(300));
assertThat(afterHostConfig.getCpuShares(), is(512));
assertThat(afterHostConfig.getCpuPeriod(), is(100000));
assertThat(afterHostConfig.getCpuQuota(), is(50000));
assertThat(afterHostConfig.getCpusetMems(), is("0"));
// assertThat(afterHostConfig.getMemoryReservation(), is(209715200L));
// assertThat(afterHostConfig.getMemorySwap(), is(514288000L));
}