本文整理汇总了Java中com.spotify.docker.client.messages.ContainerCreation类的典型用法代码示例。如果您正苦于以下问题:Java ContainerCreation类的具体用法?Java ContainerCreation怎么用?Java ContainerCreation使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ContainerCreation类属于com.spotify.docker.client.messages包,在下文中一共展示了ContainerCreation类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run
import com.spotify.docker.client.messages.ContainerCreation; //导入依赖的package包/类
public Future<TaskResult> run(Task task) {
validateTask(task);
final String functionName = task.getName();
cleanContainers(functionName);
final ContainerConfig containerConfig = prepareContainer(task);
try {
final ContainerCreation container = dockerClient.createContainer(containerConfig);
final String containerId = container.id();
dockerClient.startContainer(containerId);
final Boolean containerStatus = dockerClient.inspectContainer(containerId).state().running();
if (!containerStatus) {
cleanContainers(functionName);
}
final TaskId taskId = new TaskId(functionName, containerId);
return SimpleFuture.success(TaskResult.builder().taskId(taskId).success(containerStatus).build());
} catch (Exception e) {
log.error("create container failed: " + e.getMessage(), e);
cleanContainers(functionName);
return SimpleFuture.failed(e);
}
}
示例2: create
import com.spotify.docker.client.messages.ContainerCreation; //导入依赖的package包/类
@Override
public Container create(final String image, final String scripts) {
try {
final ContainerCreation container = this.client.createContainer(
ContainerConfig
.builder()
.image(image)
.cmd("/bin/bash", "-c", scripts)
.build()
);
return new Docker(container.id(), this);
} catch (final DockerException | InterruptedException ex) {
throw new IllegalStateException(
"Exception when creating the container "
+ "with image: " + image + " and scripts: " + scripts, ex
);
}
}
示例3: startInstance
import com.spotify.docker.client.messages.ContainerCreation; //导入依赖的package包/类
@Override
public ContainerCloudInstance startInstance(@NotNull String instanceId, @NotNull ContainerCloudImage image, @NotNull CloudInstanceUserData tag) {
try {
LOG.debug("Pulling image " + image.getId());
dockerClient.pull(image.getId());
List<String> environment = new ArrayList<>();
tag.getCustomAgentConfigurationParameters().forEach((key, value) -> environment.add(key + "=" + value));
ContainerConfig cfg = ContainerConfig.builder()
.image(image.getId())
.env(environment)
.build();
ContainerCreation creation = dockerClient.createContainer(cfg, instanceId);
LOG.debug("Starting image " + image.getId());
dockerClient.startContainer(creation.id());
return new ContainerCloudInstance(instanceId, image, this);
} catch (Exception e) {
throw new CloudException("Failed to start instance of image " + image.getId(), e);
}
}
示例4: runContainer
import com.spotify.docker.client.messages.ContainerCreation; //导入依赖的package包/类
public String runContainer(ContainerConfig.Builder containerConfigBuilder, String containerName) throws DockerException {
try {
final ContainerConfig containerConfig = containerConfigBuilder.build();
final ContainerCreation creation;
creation = dockerClient.createContainer(containerConfig, containerName);
final String id = creation.id();
dockerClient.startContainer(id);
return id;
} catch (InterruptedException e) {
logger.error("", e);
}
return null;
}
示例5: create
import com.spotify.docker.client.messages.ContainerCreation; //导入依赖的package包/类
public static DockerContainer create(CreateAgentRequest request, PluginSettings settings, DockerClient docker) throws InterruptedException, DockerException, IOException {
String containerName = UUID.randomUUID().toString();
HashMap<String, String> labels = labelsFrom(request);
String imageName = image(request.properties());
List<String> env = environmentFrom(request, settings, containerName);
try {
docker.inspectImage(imageName);
} catch (ImageNotFoundException ex) {
LOG.info("Image " + imageName + " not found, attempting to download.");
docker.pull(imageName);
}
ContainerConfig.Builder containerConfigBuilder = ContainerConfig.builder();
if (StringUtils.isNotBlank(request.properties().get("Command"))) {
containerConfigBuilder.cmd(splitIntoLinesAndTrimSpaces(request.properties().get("Command")).toArray(new String[]{}));
}
final String hostConfig = request.properties().get("Hosts");
ContainerConfig containerConfig = containerConfigBuilder
.image(imageName)
.labels(labels)
.env(env)
.hostConfig(HostConfig.builder().extraHosts(new Hosts(hostConfig)).build())
.build();
ContainerCreation container = docker.createContainer(containerConfig, containerName);
String id = container.id();
ContainerInfo containerInfo = docker.inspectContainer(id);
LOG.debug("Created container " + containerName);
docker.startContainer(containerName);
LOG.debug("container " + containerName + " started");
return new DockerContainer(containerName, containerInfo.created(), request.properties(), request.environment());
}
示例6: start
import com.spotify.docker.client.messages.ContainerCreation; //导入依赖的package包/类
@Override
public void start(WorkflowInstance workflowInstance, RunSpec runSpec) {
final String imageTag = runSpec.imageName().contains(":")
? runSpec.imageName()
: runSpec.imageName() + ":latest";
final ContainerCreation creation;
try {
boolean found = false;
for (Image image : client.listImages()) {
found |= image.repoTags().contains(imageTag);
}
if (!found) {
client.pull(imageTag, System.out::println); // blocking
}
final ContainerConfig containerConfig = ContainerConfig.builder()
.image(imageTag)
.cmd(runSpec.args())
.build();
creation = client.createContainer(containerConfig, runSpec.executionId());
client.startContainer(creation.id());
} catch (DockerException | InterruptedException e) {
throw new RuntimeException(e);
}
inFlight.put(creation.id(), workflowInstance);
LOG.info("Started container with id " + creation.id() + " and name " + runSpec.executionId());
}
示例7: testCreateContainer
import com.spotify.docker.client.messages.ContainerCreation; //导入依赖的package包/类
@Test
public void testCreateContainer() throws Exception, MccyException {
ContainerRequest request = new ContainerRequest();
request.setName("server-1");
request.setStartOnCreate(true);
request.setAckEula(true);
when(dockerClient.createContainer(any(ContainerConfig.class), anyString()))
.thenReturn(new ContainerCreation("id-1"));
ContainerConfig stubbedConfig = ContainerConfig.builder().build();
when(containerBuilderService.buildContainerConfig(any(), any(), any()))
.thenReturn(stubbedConfig);
final UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromUriString("http://localhost:8080");
containersService.setProxyUriBuilder(uriComponentsBuilder);
final String id = containersService.create(request, "user1",
containerCreateStatus -> {});
verify(dockerClient).pull(anyString(), any(ProgressHandler.class));
final ArgumentCaptor<ContainerConfig> containerConfigCaptor =
ArgumentCaptor.forClass(ContainerConfig.class);
verify(dockerClient).createContainer(containerConfigCaptor.capture(), eq("server_1"));
verify(dockerClient).startContainer(eq(id));
Mockito.verifyNoMoreInteractions(dockerClient);
assertThat(id, not(isEmptyOrNullString()));
assertEquals(id, "id-1");
}
示例8: startContainer
import com.spotify.docker.client.messages.ContainerCreation; //导入依赖的package包/类
private void startContainer() throws Exception {
final DockerClient dockerClient = DefaultDockerClient.fromEnv().build();
logger.info("Pulling image spotify/kafka");
dockerClient.pull("spotify/kafka");
final String[] ports = {"2181", "9092"};
List<String> env = new ArrayList<>();
env.add("ADVERTISED_PORT=9092");
env.add("ADVERTISED_HOST=192.168.59.103");
final Map<String, List<PortBinding>> portBindings = new HashMap<>();
for (String port : ports) {
List<PortBinding> hostPorts = new ArrayList<>();
hostPorts.add(PortBinding.of("0.0.0.0", port));
portBindings.put(port, hostPorts);
}
final HostConfig hostConfig = HostConfig.builder().portBindings(portBindings).build();
final ContainerConfig containerConfig = ContainerConfig.builder()
.hostConfig(hostConfig)
.image("spotify/kafka")
.exposedPorts(ports)
.env(env)
.build();
final ContainerCreation creation = dockerClient.createContainer(containerConfig);
containerId = creation.id();
logger.info("Starting container");
// Start container
dockerClient.startContainer(containerId);
}
示例9: execute
import com.spotify.docker.client.messages.ContainerCreation; //导入依赖的package包/类
/**
* Executes a containerized command on AWS.
*/
public String execute(String dockerImage, List<String> envList, List<String> commandList, String entryPoint) throws CommandExecutionException {
try( DockerClient dockerClient = new DefaultDockerClient("unix:///var/run/docker.sock")) {
String response = null;
//pullImage(dockerClient, dockerImage);
dockerClient.pull(dockerImage);
if (commandList != null && !commandList.isEmpty()) {
if (commandList.get(0).equalsIgnoreCase(entryPoint)) {
commandList = commandList.subList(1, commandList.size());
}
}
final ContainerConfig containerConfig = ContainerConfig.builder()
.image(dockerImage)
.env(envList)
.entrypoint(entryPoint)
.cmd(commandList)
.build();
final ContainerCreation container = dockerClient.createContainer(containerConfig);
final String containerId = container.id();
dockerClient.startContainer(containerId);
// Wait for the container to exit.
// If we don't wait, docker.logs() might return an epmty string because the container
// cmd hasn't run yet.
dockerClient.waitContainer(containerId);
final String log;
try (LogStream logs = dockerClient.logs(containerId, stdout(), stderr())) {
log = logs.readFully();
}
logger.info(log);
response = log;
dockerClient.removeContainer(containerId);
return response;
} catch (DockerException | InterruptedException e) {
throw new CommandExecutionException(e);
}
}
示例10: commitContainer
import com.spotify.docker.client.messages.ContainerCreation; //导入依赖的package包/类
@Override
public ContainerCreation commitContainer(String string, String string1, String string2, ContainerConfig cc, String string3, String string4) {
throw new IllegalStateException(DISCONNECTED);
}
示例11: createContainer
import com.spotify.docker.client.messages.ContainerCreation; //导入依赖的package包/类
@Override
public ContainerCreation createContainer(ContainerConfig cc) {
throw new IllegalStateException(DISCONNECTED);
}