ContainerApi Class — spring-boot Architecture
Architecture documentation for the ContainerApi class in DockerApi.java from the spring-boot codebase.
Entity Profile
Relationship Graph
Source Code
buildpack/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/DockerApi.java lines 405–506
public class ContainerApi {
ContainerApi() {
}
/**
* Create a new container a {@link ContainerConfig}.
* @param config the container config
* @param platform the platform (os/architecture/variant) of the image the
* container should be created from
* @param contents additional contents to include
* @return a {@link ContainerReference} for the newly created container
* @throws IOException on IO error
*/
public ContainerReference create(ContainerConfig config, @Nullable ImagePlatform platform,
ContainerContent... contents) throws IOException {
Assert.notNull(config, "'config' must not be null");
Assert.noNullElements(contents, "'contents' must not contain null elements");
ContainerReference containerReference = createContainer(config, platform);
for (ContainerContent content : contents) {
uploadContainerContent(containerReference, content);
}
return containerReference;
}
private ContainerReference createContainer(ContainerConfig config, @Nullable ImagePlatform platform)
throws IOException {
URI createUri = (platform != null)
? buildUrl(Feature.PLATFORM_CONTAINER_CREATE, "/containers/create", "platform", platform)
: buildUrl("/containers/create");
try (Response response = http().post(createUri, "application/json", config::writeTo)) {
return ContainerReference
.of(SharedJsonMapper.get().readTree(response.getContent()).at("/Id").asString());
}
}
private void uploadContainerContent(ContainerReference reference, ContainerContent content) throws IOException {
URI uri = buildUrl("/containers/" + reference + "/archive", "path", content.getDestinationPath());
http().put(uri, "application/x-tar", content.getArchive()::writeTo).close();
}
/**
* Start a specific container.
* @param reference the container reference to start
* @throws IOException on IO error
*/
public void start(ContainerReference reference) throws IOException {
Assert.notNull(reference, "'reference' must not be null");
URI uri = buildUrl("/containers/" + reference + "/start");
http().post(uri).close();
}
/**
* Return and follow logs for a specific container.
* @param reference the container reference
* @param listener a listener to receive log update events
* @throws IOException on IO error
*/
public void logs(ContainerReference reference, UpdateListener<LogUpdateEvent> listener) throws IOException {
Assert.notNull(reference, "'reference' must not be null");
Assert.notNull(listener, "'listener' must not be null");
Object[] params = { "stdout", "1", "stderr", "1", "follow", "1" };
URI uri = buildUrl("/containers/" + reference + "/logs", params);
listener.onStart();
try {
try (Response response = http().get(uri)) {
LogUpdateEvent.readAll(response.getContent(), listener::onUpdate);
}
}
finally {
listener.onFinish();
}
}
/**
* Wait for a container to stop and retrieve the status.
* @param reference the container reference
* @return a {@link ContainerStatus} indicating the exit status of the container
* @throws IOException on IO error
*/
public ContainerStatus wait(ContainerReference reference) throws IOException {
Assert.notNull(reference, "'reference' must not be null");
URI uri = buildUrl("/containers/" + reference + "/wait");
try (Response response = http().post(uri)) {
return ContainerStatus.of(response.getContent());
}
}
/**
* Remove a specific container.
* @param reference the container to remove
* @param force if removal should be forced
* @throws IOException on IO error
*/
public void remove(ContainerReference reference, boolean force) throws IOException {
Assert.notNull(reference, "'reference' must not be null");
Collection<String> params = force ? FORCE_PARAMS : Collections.emptySet();
URI uri = buildUrl("/containers/" + reference, params);
http().delete(uri).close();
}
}
Domain
Source
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free