How can I log docker-java operations to the console?

456 Views Asked by At

I'm using the docker-java library in a command-line project, doing things like this:

    private DockerClient client;

    public Docker() {
        var config = DefaultDockerClientConfig
            .createDefaultConfigBuilder()
            .withDockerHost("tcp://localhost:2375")
            .build();
        client = DockerClientBuilder
            .getInstance(config)
            .build();
    }

    public String build(String name, Path dockerFilePath) throws InterruptedException {
        System.out.println("Building image from: " + dockerFilePath.toString());
        var tags = new HashSet<String>();
        tags.add(name);
        return client
            .buildImageCmd()
            .withNoCache(true)
            .withDockerfile(dockerFilePath.toFile())
            .withTags(tags)
            .start()
            .awaitCompletion()
            .awaitImageId();
    }

When I run the build method, my app hangs. I'd troubleshoot that myself, but I can't see what's happening; there's no output in the console.

Hence my question:

Is there a way I can configure this library so that the Docker output logs to the Windows console?

0

There are 0 best solutions below