本文整理汇总了Java中com.spotify.docker.client.messages.ContainerCreation.id方法的典型用法代码示例。如果您正苦于以下问题:Java ContainerCreation.id方法的具体用法?Java ContainerCreation.id怎么用?Java ContainerCreation.id使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.spotify.docker.client.messages.ContainerCreation
的用法示例。
在下文中一共展示了ContainerCreation.id方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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;
}
示例4: 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());
}
示例5: 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);
}
示例6: 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);
}
}