我正在尝试使用docker-java从java使用docker远程API,我正在努力寻找一种方法来查看容器的执行何时完成:

 CreateContainerResponse container = dockerClient.createContainerCmd("me/vw:v0.1")
                .withVolumes(workingDIR)
                .withBinds(new Bind("/localDrive", workingDIR))
                .withCmd("vw", "/rcv1/rcv1.train.vw.gz", "--cache_file", "/rcv1/cache_train", "-f", "/rcv1/r_temp")
                .withLogConfig(logconf)
                .exec();
        dockerClient.startContainerCmd((container.getId())).exec();

        Thread.sleep(10000); //OBVIOUSLY BROKEN HACK IS BROKEN
        System.out.println("PRINTING LOGS");
        System.out.println(containerLog(container.getId(), dockerClient));

检查容器是否完成的正常方法是什么?我是否必须编写轮询Docker服务器的内容,或者是否有一些便捷的阻止功能/调用? docker-java的文档非常糟糕,我要做的大部分工作都是查看测试用例。

干杯,

缺口

最佳答案

dockerClient.startContainerCmd(createContainerResponse.getId()).exec();
WaitContainerResultCallback resultCallback = new WaitContainerResultCallback();
dockerClient.waitContainerCmd(createContainerResponse.getId()).exec(resultCallback);
resultCallback.awaitCompletion();
dockerClient.removeContainerCmd(createContainerResponse.getId()).exec();

08-28 22:10