DefaultDockerCompose Class — spring-boot Architecture
Architecture documentation for the DefaultDockerCompose class in DefaultDockerCompose.java from the spring-boot codebase.
Entity Profile
Relationship Graph
Source Code
core/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/core/DefaultDockerCompose.java lines 40–142
class DefaultDockerCompose implements DockerCompose {
private final DockerCli cli;
private final DockerHost hostname;
DefaultDockerCompose(DockerCli cli, @Nullable String host) {
this.cli = cli;
this.hostname = DockerHost.get(host, () -> cli.run(new DockerCliCommand.Context()));
}
@Override
public void up(LogLevel logLevel) {
up(logLevel, Collections.emptyList());
}
@Override
public void up(LogLevel logLevel, List<String> arguments) {
this.cli.run(new DockerCliCommand.ComposeUp(logLevel, arguments));
}
@Override
public void down(Duration timeout) {
down(timeout, Collections.emptyList());
}
@Override
public void down(Duration timeout, List<String> arguments) {
this.cli.run(new DockerCliCommand.ComposeDown(timeout, arguments));
}
@Override
public void start(LogLevel logLevel) {
start(logLevel, Collections.emptyList());
}
@Override
public void start(LogLevel logLevel, List<String> arguments) {
this.cli.run(new DockerCliCommand.ComposeStart(logLevel, arguments));
}
@Override
public void stop(Duration timeout) {
stop(timeout, Collections.emptyList());
}
@Override
public void stop(Duration timeout, List<String> arguments) {
this.cli.run(new DockerCliCommand.ComposeStop(timeout, arguments));
}
@Override
public boolean hasDefinedServices() {
return !this.cli.run(new DockerCliCommand.ComposeConfig()).services().isEmpty();
}
@Override
public List<RunningService> getRunningServices() {
List<DockerCliComposePsResponse> runningPsResponses = runComposePs().stream().filter(this::isRunning).toList();
if (runningPsResponses.isEmpty()) {
return Collections.emptyList();
}
DockerComposeFile dockerComposeFile = this.cli.getDockerComposeFile();
List<RunningService> result = new ArrayList<>();
Map<String, DockerCliInspectResponse> inspected = inspect(runningPsResponses);
for (DockerCliComposePsResponse psResponse : runningPsResponses) {
DockerCliInspectResponse inspectResponse = inspectContainer(psResponse.id(), inspected);
Assert.state(inspectResponse != null, () -> "Failed to inspect container '%s'".formatted(psResponse.id()));
result.add(new DefaultRunningService(this.hostname, dockerComposeFile, psResponse, inspectResponse));
}
return Collections.unmodifiableList(result);
}
private Map<String, DockerCliInspectResponse> inspect(List<DockerCliComposePsResponse> runningPsResponses) {
List<String> ids = runningPsResponses.stream().map(DockerCliComposePsResponse::id).toList();
List<DockerCliInspectResponse> inspectResponses = this.cli.run(new DockerCliCommand.Inspect(ids));
return inspectResponses.stream().collect(Collectors.toMap(DockerCliInspectResponse::id, Function.identity()));
}
private @Nullable DockerCliInspectResponse inspectContainer(String id,
Map<String, DockerCliInspectResponse> inspected) {
DockerCliInspectResponse inspect = inspected.get(id);
if (inspect != null) {
return inspect;
}
// Docker Compose v2.23.0 returns truncated ids, so we have to do a prefix match
for (Entry<String, DockerCliInspectResponse> entry : inspected.entrySet()) {
if (entry.getKey().startsWith(id)) {
return entry.getValue();
}
}
return null;
}
private List<DockerCliComposePsResponse> runComposePs() {
return this.cli.run(new DockerCliCommand.ComposePs());
}
private boolean isRunning(DockerCliComposePsResponse psResponse) {
return !"exited".equals(psResponse.state());
}
}
Domain
Source
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free