private void findImageNamesInDockerfile(String serviceName, Map<String, ?> serviceDefinitionMap) {
        final Object buildNode = serviceDefinitionMap.get("build");
        Path dockerfilePath = null;

        if (buildNode instanceof Map) {
            final Map<?, ?> buildElement = (Map<?, ?>) buildNode;
            final Object dockerfileRelativePath = buildElement.get("dockerfile");
            final Object contextRelativePath = buildElement.get("context");
            if (dockerfileRelativePath instanceof String && contextRelativePath instanceof String) {
                dockerfilePath =
                    composeFile
                        .getAbsoluteFile()
                        .getParentFile()
                        .toPath()
                        .resolve((String) contextRelativePath)
                        .resolve((String) dockerfileRelativePath)
                        .normalize();
            }
        } else if (buildNode instanceof String) {
            dockerfilePath =
                composeFile
                    .getAbsoluteFile()
                    .getParentFile()
                    .toPath()
                    .resolve((String) buildNode)
                    .resolve("./Dockerfile")
                    .normalize();
        }

        if (dockerfilePath != null && Files.exists(dockerfilePath)) {
            Set<String> resolvedImageNames = new ParsedDockerfile(dockerfilePath).getDependencyImageNames();
            if (!resolvedImageNames.isEmpty()) {
                log.debug(
                    "Resolved Dockerfile dependency images for Docker Compose in {} -> {}: {}",
                    composeFileName,
                    dockerfilePath,
                    resolvedImageNames
                );
                this.serviceNameToImageNames.put(serviceName, resolvedImageNames);
            }
        }
    }
Representation of a docker-compose file, with partial parsing for validation and extraction of a minimal set of
data.
core/src/main/java/org/testcontainers/containers/ParsedDockerComposeFile.java