本文整理汇总了Java中com.github.dockerjava.api.command.CreateContainerCmd类的典型用法代码示例。如果您正苦于以下问题:Java CreateContainerCmd类的具体用法?Java CreateContainerCmd怎么用?Java CreateContainerCmd使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CreateContainerCmd类属于com.github.dockerjava.api.command包,在下文中一共展示了CreateContainerCmd类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: build
import com.github.dockerjava.api.command.CreateContainerCmd; //导入依赖的package包/类
@Override
public CreateContainerCmd build(TestDescriptor td, CreateContainerCmd cmd, Volume v) {
Bind[] binds = cmd.getBinds();
String hostPath = v.useClasspath()
? Thread.currentThread().getContextClassLoader()
.getResource(v.host()).getPath()
: v.host();
Bind bind = new Bind(hostPath,
new com.github.dockerjava.api.model.Volume(v.container()),
AccessMode.fromBoolean(v.accessMode().equals(Volume.AccessMode.RW)));
List<Bind> bindsList = new ArrayList<>();
if(binds != null) {
bindsList.addAll(Arrays.asList(binds));
}
bindsList.add(bind);
return cmd.withBinds(bindsList);
}
示例2: createContainer
import com.github.dockerjava.api.command.CreateContainerCmd; //导入依赖的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();
}
示例3: build
import com.github.dockerjava.api.command.CreateContainerCmd; //导入依赖的package包/类
@Override
public CreateContainerCmd build(TestDescriptor td, CreateContainerCmd cmd, WebHealthCheck whc) {
final String serviceNameEnv = SERVICE_PREFIX + whc.exposedPort() + SERVICE_NAME_SUFFIX + "=" + td.getNamed().value();
final String serviceCheckScriptEnv = SERVICE_CHECK_SCRIPT + "=`which curl` -f "
+ (whc.protocol().equals(WebProtocol.HTTPS) ? "-sSk " : "")
+ whc.protocol().toString().toLowerCase()
+ "://$SERVICE_IP:$SERVICE_PORT"
+ whc.endpoint();
final String serviceCheckIntervalEnv = SERVICE_CHECK_INTERVAL + "=" + whc.pollingInterval() + "s";
List<String> finalEnv = new ArrayList<>();
List<String> healthCheckEnv = Arrays.asList(serviceNameEnv, serviceCheckScriptEnv, serviceCheckIntervalEnv);
finalEnv.addAll(healthCheckEnv);
String[] env = cmd.getEnv();
if(env != null) {
finalEnv.addAll(Arrays.asList(env));
}
return cmd.withEnv(finalEnv);
}
示例4: dockerCommand
import com.github.dockerjava.api.command.CreateContainerCmd; //导入依赖的package包/类
@Override
protected CreateContainerCmd dockerCommand() {
int port = getServicePort();
ExposedPort exposedPort = ExposedPort.tcp(port);
Ports portBindings = new Ports();
if (getCluster().isMapPortsToHost()) {
portBindings.bind(exposedPort, Ports.Binding.bindPort(port));
}
CreateContainerCmd cmd = DockerClientFactory.build().createContainerCmd(getImageName() + ":" + getImageTag())
.withName(getName())
.withExposedPorts(new ExposedPort(getServicePort()))
.withEnv(newEnvironment()
.withValues(getMesosMasterEnvVars())
.withValues(getSharedEnvVars())
.createEnvironment())
.withPortBindings(portBindings);
MesosDns mesosDns = getCluster().getMesosDns();
if (mesosDns != null) {
cmd.withDns(mesosDns.getIpAddress());
}
return cmd;
}
示例5: dockerCommand
import com.github.dockerjava.api.command.CreateContainerCmd; //导入依赖的package包/类
@Override
protected CreateContainerCmd dockerCommand() {
int port = getServicePort();
ExposedPort exposedPort = ExposedPort.tcp(port);
Ports portBindings = new Ports();
if (getCluster().isMapPortsToHost()) {
portBindings.bind(exposedPort, Ports.Binding.bindPort(port));
}
ExposedPort consulHTTPPort = ExposedPort.tcp(ConsulConfig.CONSUL_HTTP_PORT);
ExposedPort consulDNSPort = ExposedPort.udp(ConsulConfig.CONSUL_DNS_PORT);
return DockerClientFactory.build().createContainerCmd(config.getImageName() + ":" + config.getImageTag())
.withName(getName())
.withCmd("agent", "-server", "-bootstrap", "-client", "0.0.0.0")
.withExposedPorts(consulHTTPPort, consulDNSPort)
.withPortBindings(portBindings);
}
示例6: runInsideDocker
import com.github.dockerjava.api.command.CreateContainerCmd; //导入依赖的package包/类
private <T> T runInsideDocker(DockerClient client, Consumer<CreateContainerCmd> createContainerCmdConsumer, BiFunction<DockerClient, String, T> block) {
checkAndPullImage(client, TINY_IMAGE);
CreateContainerCmd createContainerCmd = client.createContainerCmd(TINY_IMAGE);
createContainerCmdConsumer.accept(createContainerCmd);
String id = createContainerCmd.exec().getId();
try {
client.startContainerCmd(id).exec();
return block.apply(client, id);
} finally {
try {
client.removeContainerCmd(id).withRemoveVolumes(true).withForce(true).exec();
} catch (NotFoundException | InternalServerErrorException ignored) {
log.debug("", ignored);
}
}
}
示例7: startNode
import com.github.dockerjava.api.command.CreateContainerCmd; //导入依赖的package包/类
public void startNode(String id, BrowserType browserType, String nodeName, String imageId,
String hubIp) {
// Create node if not exist
if (!existsContainer(nodeName)) {
pullImageIfNecessary(imageId, false);
log.debug("Creating container {}", nodeName);
CreateContainerCmd createContainerCmd =
getClient().createContainerCmd(imageId).withName(nodeName);
// TODO make this port configurable
createContainerCmd.withEnv(new String[] { "HUB_PORT_4444_TCP_ADDR=" + hubIp, "HUB_PORT_4444_TCP_PORT=4444" });
createContainerCmd.exec();
log.debug("Container {} started...", nodeName);
} else {
log.debug("Container {} already exists", nodeName);
}
// Start node if stopped
startContainer(nodeName);
}
示例8: testPortBinding
import com.github.dockerjava.api.command.CreateContainerCmd; //导入依赖的package包/类
@Test
public void testPortBinding() throws IOException, InterruptedException {
DockerComputerSSHConnector connector = new DockerComputerSSHConnector(Mockito.mock(DockerComputerSSHConnector.SSHKeyStrategy.class));
CreateContainerCmdImpl cmd = new CreateContainerCmdImpl(Mockito.mock(CreateContainerCmd.Exec.class), "");
cmd.withPortBindings(PortBinding.parse("42:42"));
connector.setPort(22);
connector.beforeContainerCreated(Mockito.mock(DockerAPI.class), "/workdir", cmd);
final Ports portBindings = cmd.getPortBindings();
Assert.assertNotNull(portBindings);
final Map<ExposedPort, Ports.Binding[]> bindingMap = portBindings.getBindings();
Assert.assertNotNull(bindingMap);
Assert.assertEquals(2, bindingMap.size());
final Ports.Binding[] configuredBindings = bindingMap.get(new ExposedPort(42));
Assert.assertNotNull(configuredBindings);
Assert.assertEquals(1, configuredBindings.length);
Assert.assertEquals("42", configuredBindings[0].getHostPortSpec());
final Ports.Binding[] sshBindings = bindingMap.get(new ExposedPort(22));
Assert.assertNotNull(sshBindings);
Assert.assertEquals(1, sshBindings.length);
Assert.assertNull(sshBindings[0].getHostPortSpec());
System.out.println();
}
示例9: resolveExposedPorts
import com.github.dockerjava.api.command.CreateContainerCmd; //导入依赖的package包/类
private Set<ExposedPort> resolveExposedPorts(CubeContainer containerConfiguration,
CreateContainerCmd createContainerCmd) {
Set<ExposedPort> allExposedPorts = new HashSet<>();
if (containerConfiguration.getPortBindings() != null) {
for (PortBinding binding : containerConfiguration.getPortBindings()) {
allExposedPorts.add(new ExposedPort(binding.getExposedPort().getExposed(),
InternetProtocol.parse(binding.getExposedPort().getType())));
}
}
if (containerConfiguration.getExposedPorts() != null) {
for (org.arquillian.cube.docker.impl.client.config.ExposedPort port : containerConfiguration.getExposedPorts()) {
allExposedPorts.add(new ExposedPort(port.getExposed(), InternetProtocol.parse(port.getType())));
}
}
return allExposedPorts;
}
示例10: runContainer
import com.github.dockerjava.api.command.CreateContainerCmd; //导入依赖的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;
}
示例11: build
import com.github.dockerjava.api.command.CreateContainerCmd; //导入依赖的package包/类
@Override
public CreateContainerCmd build(TestDescriptor td, CreateContainerCmd cmd, PortBindings pbs) {
for (PortBinding pb : pbs.value()) {
cmd = builder.build(td, cmd, pb);
}
return cmd;
}
示例12: build
import com.github.dockerjava.api.command.CreateContainerCmd; //导入依赖的package包/类
@Override
public CreateContainerCmd build(TestDescriptor td, CreateContainerCmd cmd, Env t) {
String[] env = cmd.getEnv();
List<String> finalEnv = new ArrayList<>();
finalEnv.addAll(Arrays.asList(t.value()));
if (env != null) {
finalEnv.addAll(Arrays.asList(env));
}
return cmd.withEnv(finalEnv);
}
示例13: build
import com.github.dockerjava.api.command.CreateContainerCmd; //导入依赖的package包/类
@Override
public CreateContainerCmd build(TestDescriptor td, CreateContainerCmd cmd, Volumes vs) {
for (Volume v : vs.value()) {
cmd = builder.build(td, cmd, v);
}
return cmd;
}
示例14: createInstance
import com.github.dockerjava.api.command.CreateContainerCmd; //导入依赖的package包/类
private ServiceInstance createInstance(TestDescriptor descriptor, DockerClient client, int i) {
CreateContainerCmd cmd = client.createContainerCmd(descriptor.getImage().value());
cmd = computeContainerName(descriptor, i, cmd);
cmd = executeOptionBuilders(descriptor, cmd);
if (descriptor.getCustomisationHook() != null) {
cmd = executeCustomisationHook(descriptor.getCustomisationHook(), descriptor.getInstance(), cmd);
}
String containerId = null;
Status status = null;
String statusDetails = null;
try {
containerId = createAndStartContainer(cmd, descriptor.getImage().pull(), client);
status = Status.STARTED;
statusDetails = "Started.";
} catch (Throwable t) {
if(t instanceof CompletionException) {
if(t.getCause() != null && t.getCause() instanceof ContainerException) {
containerId = ((ContainerException) t.getCause()).getContainerId();
statusDetails = t.getCause().getCause() != null ? t.getCause().getCause().getMessage() : null;
} else {
statusDetails = t.getCause() != null ? t.getCause().getMessage() : null;
}
} else {
statusDetails = t.getMessage();
}
status = Status.ABORTED;
}
return ServiceInstance.builder()
.containerName(cmd.getName())
.containerId(containerId)
.status(status)
.statusDetails(statusDetails)
.build();
}
示例15: computeContainerName
import com.github.dockerjava.api.command.CreateContainerCmd; //导入依赖的package包/类
private CreateContainerCmd computeContainerName(TestDescriptor dependency, int i, CreateContainerCmd cmd) {
if (!dependency.getContainerName()
.isEmpty()) {
String name = dependency.getReplicas() > 1
? dependency.getContainerName() + "-" + (i + 1)
: dependency.getContainerName();
cmd = cmd.withName(name);
}
return cmd;
}