本文整理汇总了Java中com.github.dockerjava.api.command.CreateContainerResponse类的典型用法代码示例。如果您正苦于以下问题:Java CreateContainerResponse类的具体用法?Java CreateContainerResponse怎么用?Java CreateContainerResponse使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CreateContainerResponse类属于com.github.dockerjava.api.command包,在下文中一共展示了CreateContainerResponse类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readFileFromContainer
import com.github.dockerjava.api.command.CreateContainerResponse; //导入依赖的package包/类
@Nullable
private byte[] readFileFromContainer(@NonNull final DockerClient _dockerClient,
@NonNull final CreateContainerResponse _container,
@NonNull final String _outputFile) {
final InputStream fileStream =_dockerClient
.copyArchiveFromContainerCmd(_container.getId(), _outputFile)
.exec();
final TarArchiveInputStream tarIn = new TarArchiveInputStream(fileStream);
try {
if (tarIn.getNextEntry() == null) {
log.error("No entry in tar archive");
return null;
}
return IOUtils.toByteArray(tarIn);
} catch (IOException _e) {
log.error("Could not read file from container", _e);
return null;
}
}
示例2: runCommand
import com.github.dockerjava.api.command.CreateContainerResponse; //导入依赖的package包/类
private boolean runCommand(@NonNull final DockerClient _dockerClient,
@NonNull final CreateContainerResponse _container,
@NonNull final String[] _commandWithArguments) {
final ExecCreateCmdResponse mExecCreateCmdResponse = _dockerClient
.execCreateCmd(_container.getId())
.withAttachStdout(true)
.withCmd(_commandWithArguments)
.exec();
try {
return _dockerClient
.execStartCmd(mExecCreateCmdResponse.getId())
.exec(new ExecStartResultCallback() {
@Override
public void onNext(Frame frame) {
super.onNext(frame);
}
})
.awaitCompletion(30, TimeUnit.MINUTES);
} catch (InterruptedException e) {
// ignore
}
return false;
}
示例3: stopAndRemoveContainer
import com.github.dockerjava.api.command.CreateContainerResponse; //导入依赖的package包/类
private void stopAndRemoveContainer(@NonNull final DockerClient _dockerClient,
@NonNull final CreateContainerResponse _container) {
_dockerClient
.stopContainerCmd(_container.getId())
.withTimeout(0)
.exec();
try {
_dockerClient
.waitContainerCmd(_container.getId())
.exec(new WaitContainerResultCallback())
.awaitCompletion();
} catch (InterruptedException e) {
// ignore
}
_dockerClient
.removeContainerCmd(_container.getId())
.exec();
}
示例4: verify_container_command
import com.github.dockerjava.api.command.CreateContainerResponse; //导入依赖的package包/类
@Test
public void verify_container_command ()
throws Exception {
CreateContainerResponse createResponse = startNginx();
logger.info( "Started" );
String commandResult = containerCommand( createResponse.getId(), "nginx", "-v" );
// commandResult = containerCommand( "/nginx", "ls", "-l" ) ;
logger.info( "Command output: {}", commandResult );
assertThat( commandResult )
.as( "version message" )
.contains( "nginx version" );
logger.info( "Started success, removing: {}", createResponse.getId() );
dockerClient
.removeContainerCmd( createResponse.getId() )
.withForce( true )
.exec();
}
示例5: testWithAContainerWithAPort
import com.github.dockerjava.api.command.CreateContainerResponse; //导入依赖的package包/类
@Test
public void testWithAContainerWithAPort() throws InterruptedException {
CreateContainerResponse container = client.createContainerCmd("nginx")
.withExposedPorts(ExposedPort.tcp(80), ExposedPort.tcp(443))
.withPortBindings(PortBinding.parse("80"))
.exec();
AtomicBoolean done = new AtomicBoolean();
Future<Void> future = Future.future();
future.setHandler(ar -> done.set(ar.succeeded()));
bridge.scan(future);
await().untilAtomic(done, is(true));
assertThat(bridge.getServices()).hasSize(0);
done.set(false);
client.startContainerCmd(container.getId()).exec();
Future<Void> future2 = Future.future();
future2.setHandler(ar -> done.set(ar.succeeded()));
bridge.scan(future2);
await().untilAtomic(done, is(true));
assertThat(bridge.getServices()).hasSize(1);
DockerService service = bridge.getServices().get(0);
assertThat(service.records()).hasSize(1);
}
示例6: 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();
}
示例7: defaultRunCommand
import com.github.dockerjava.api.command.CreateContainerResponse; //导入依赖的package包/类
@Override
public void defaultRunCommand(String eclipseProjectName, String dockerBuildContext) {
ExposedPort tcp8080 = ExposedPort.tcp(8080);
CreateContainerResponse container = dockerClient.createContainerCmd("mariolet/my-tomcat")
.withCmd("true")
.withExposedPorts(tcp8080)
.exec();
Ports portBindings = new Ports();
portBindings.bind(tcp8080, Ports.Binding(80));
dockerClient.startContainerCmd(container.getId())
.withPortBindings(portBindings)
.exec();
}
示例8: inspectContainerWithSize
import com.github.dockerjava.api.command.CreateContainerResponse; //导入依赖的package包/类
@Test()
public void inspectContainerWithSize() throws DockerException {
String containerName = "generated_" + new SecureRandom().nextInt();
CreateContainerResponse container = dockerRule.getClient().createContainerCmd("busybox").withCmd("top")
.withName(containerName).exec();
LOG.info("Created container {}", container.toString());
assertThat(container.getId(), not(isEmptyString()));
InspectContainerCmd command = dockerRule.getClient().inspectContainerCmd(container.getId()).withSize(true);
assertTrue(command.getSize());
InspectContainerResponse containerInfo = command.exec();
assertEquals(containerInfo.getId(), container.getId());
// TODO check swarm
if (isNotSwarm(dockerRule.getClient())) {
assertNotNull(containerInfo.getSizeRootFs());
assertTrue(containerInfo.getSizeRootFs().intValue() > 0);
}
}
示例9: generateEvents
import com.github.dockerjava.api.command.CreateContainerResponse; //导入依赖的package包/类
/**
* This method generates some events and returns the number of events being generated
*/
private int generateEvents() throws Exception {
String testImage = "busybox:latest";
dockerRule.getClient().pullImageCmd(testImage).exec(new PullImageResultCallback()).awaitSuccess();
CreateContainerResponse container = dockerRule.getClient().createContainerCmd(testImage).withCmd("sleep", "9999").exec();
dockerRule.getClient().startContainerCmd(container.getId()).exec();
dockerRule.getClient().stopContainerCmd(container.getId()).withTimeout(1).exec();
// generates 5 events with remote api 1.24:
// Event[status=pull,id=busybox:latest,from=<null>,node=<null>,type=IMAGE,action=pull,[email protected][id=busybox:latest,attributes={name=busybox}],time=1473455186,timeNano=1473455186436681587]
// Event[status=create,id=6ec10182cde227040bfead8547b63105e6bbc4e94b99f6098bfad6e158ce0d3c,from=busybox:latest,node=<null>,type=CONTAINER,action=create,[email protected][id=6ec10182cde227040bfead8547b63105e6bbc4e94b99f6098bfad6e158ce0d3c,attributes={image=busybox:latest, name=sick_lamport}],time=1473455186,timeNano=1473455186470713257]
// Event[status=<null>,id=<null>,from=<null>,node=<null>,type=NETWORK,action=connect,[email protected][id=10870ceb13abb7cf841ea68868472da881b33c8ed08d2cde7dbb39d7c24d1d27,attributes={container=6ec10182cde227040bfead8547b63105e6bbc4e94b99f6098bfad6e158ce0d3c, name=bridge, type=bridge}],time=1473455186,timeNano=1473455186544318466]
// Event[status=start,id=6ec10182cde227040bfead8547b63105e6bbc4e94b99f6098bfad6e158ce0d3c,from=busybox:latest,node=<null>,type=CONTAINER,action=start,[email protected][id=6ec10182cde227040bfead8547b63105e6bbc4e94b99f6098bfad6e158ce0d3c,attributes={image=busybox:latest, name=sick_lamport}],time=1473455186,timeNano=1473455186786163819]
// Event[status=kill,id=6ec10182cde227040bfead8547b63105e6bbc4e94b99f6098bfad6e158ce0d3c,from=busybox:latest,node=<null>,type=CONTAINER,action=kill,[email protected][id=6ec10182cde227040bfead8547b63105e6bbc4e94b99f6098bfad6e158ce0d3c,attributes={image=busybox:latest, name=sick_lamport, signal=15}],time=1473455186,timeNano=1473455186792963392]
return 5;
}
示例10: execStartAttached
import com.github.dockerjava.api.command.CreateContainerResponse; //导入依赖的package包/类
@Test
public void execStartAttached() throws Exception {
String containerName = "generated_" + new SecureRandom().nextInt();
CreateContainerResponse container = dockerRule.getClient().createContainerCmd("busybox").withCmd("sleep", "9999")
.withName(containerName).exec();
LOG.info("Created container {}", container.toString());
assertThat(container.getId(), not(isEmptyString()));
dockerRule.getClient().startContainerCmd(container.getId()).exec();
ExecCreateCmdResponse execCreateCmdResponse = dockerRule.getClient().execCreateCmd(container.getId())
.withAttachStdout(true).withCmd("touch", "/execStartTest.log").exec();
dockerRule.getClient().execStartCmd(execCreateCmdResponse.getId()).withDetach(false).withTty(true)
.exec(new ExecStartResultCallback(System.out, System.err)).awaitCompletion();
InputStream response = dockerRule.getClient().copyArchiveFromContainerCmd(container.getId(), "/execStartTest.log").exec();
Boolean bytesAvailable = response.available() > 0;
assertTrue( "The file was not copied from the container.", bytesAvailable);
// read the stream fully. Otherwise, the underlying stream will not be closed.
String responseAsString = asString(response);
assertNotNull(responseAsString);
assertTrue(responseAsString.length() > 0);
}
示例11: testWaitContainerTimeout
import com.github.dockerjava.api.command.CreateContainerResponse; //导入依赖的package包/类
@Test
public void testWaitContainerTimeout() throws Exception {
CreateContainerResponse container = dockerRule.getClient().createContainerCmd("busybox").withCmd("sleep", "10").exec();
LOG.info("Created container: {}", container.toString());
assertThat(container.getId(), not(isEmptyString()));
dockerRule.getClient().startContainerCmd(container.getId()).exec();
WaitContainerResultCallback callback = dockerRule.getClient().waitContainerCmd(container.getId()).exec(
new WaitContainerResultCallback());
try {
callback.awaitStatusCode(100, TimeUnit.MILLISECONDS);
throw new AssertionError("Should throw exception on timeout.");
} catch (DockerClientException e) {
LOG.info(e.getMessage());
}
}
示例12: copyDirWithLastAddedTarEntryEmptyDir
import com.github.dockerjava.api.command.CreateContainerResponse; //导入依赖的package包/类
@Test
public void copyDirWithLastAddedTarEntryEmptyDir() throws Exception{
// create a temp dir
Path localDir = Files.createTempDirectory(null);
localDir.toFile().deleteOnExit();
// create empty sub-dir with name b
Files.createDirectory(localDir.resolve("b"));
// create sub-dir with name a
Path dirWithFile = Files.createDirectory(localDir.resolve("a"));
// create file in sub-dir b, name or conter are irrelevant
Files.createFile(dirWithFile.resolve("file"));
// create a test container
CreateContainerResponse container = dockerRule.getClient().createContainerCmd("busybox")
.withCmd("sleep", "9999")
.exec();
// start the container
dockerRule.getClient().startContainerCmd(container.getId()).exec();
// copy data from local dir to container
dockerRule.getClient().copyArchiveToContainerCmd(container.getId())
.withHostResource(localDir.toString())
.exec();
// cleanup dir
FileUtils.deleteDirectory(localDir.toFile());
}
示例13: testContainerDiff
import com.github.dockerjava.api.command.CreateContainerResponse; //导入依赖的package包/类
@Test
public void testContainerDiff() throws DockerException {
CreateContainerResponse container = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE).withCmd("touch", "/test").exec();
LOG.info("Created container: {}", container.toString());
assertThat(container.getId(), not(isEmptyString()));
dockerRule.getClient().startContainerCmd(container.getId()).exec();
int exitCode = dockerRule.getClient().waitContainerCmd(container.getId()).exec(new WaitContainerResultCallback())
.awaitStatusCode();
assertThat(exitCode, equalTo(0));
List<ChangeLog> filesystemDiff = dockerRule.getClient().containerDiffCmd(container.getId()).exec();
LOG.info("Container DIFF: {}", filesystemDiff.toString());
assertThat(filesystemDiff.size(), equalTo(1));
ChangeLog testChangeLog = selectUnique(filesystemDiff, hasField("path", equalTo("/test")));
assertThat(testChangeLog, hasField("path", equalTo("/test")));
assertThat(testChangeLog, hasField("kind", equalTo(1)));
}
示例14: removeImage
import com.github.dockerjava.api.command.CreateContainerResponse; //导入依赖的package包/类
@Test
public void removeImage() throws DockerException, InterruptedException {
CreateContainerResponse container = dockerRule.getClient().createContainerCmd("busybox").withCmd("sleep", "9999").exec();
LOG.info("Created container: {}", container.toString());
assertThat(container.getId(), not(isEmptyString()));
dockerRule.getClient().startContainerCmd(container.getId()).exec();
LOG.info("Committing container {}", container.toString());
String imageId = dockerRule.getClient().commitCmd(container.getId()).exec();
dockerRule.getClient().stopContainerCmd(container.getId()).exec();
dockerRule.getClient().removeContainerCmd(container.getId()).exec();
LOG.info("Removing image: {}", imageId);
dockerRule.getClient().removeImageCmd(imageId).exec();
List<Container> containers = dockerRule.getClient().listContainersCmd().withShowAll(true).exec();
Matcher matcher = not(hasItem(hasField("id", startsWith(imageId))));
assertThat(containers, matcher);
}
示例15: copyFromContainer
import com.github.dockerjava.api.command.CreateContainerResponse; //导入依赖的package包/类
@Test
public void copyFromContainer() throws Exception {
// TODO extract this into a shared method
CreateContainerResponse container = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE)
.withName("copyFromContainer" + dockerRule.getKind())
.withCmd("touch", "/copyFromContainer")
.exec();
LOG.info("Created container: {}", container);
assertThat(container.getId(), not(isEmptyOrNullString()));
dockerRule.getClient().startContainerCmd(container.getId()).exec();
InputStream response = dockerRule.getClient().copyArchiveFromContainerCmd(container.getId(), "/copyFromContainer").exec();
Boolean bytesAvailable = response.available() > 0;
assertTrue("The file was not copied from the container.", bytesAvailable );
// read the stream fully. Otherwise, the underlying stream will not be closed.
String responseAsString = TestUtils.asString(response);
assertNotNull(responseAsString);
assertTrue(responseAsString.length() > 0);
}