Issue
I have in my code the next:
try (DockerClient client = DefaultDockerClient.fromEnv().connectTimeoutMillis(TimeUnit.SECONDS.toMillis(3)).build()) {
//some code here
}catch (DockerCertificateException e) {
log.warn("Failed to connect Docker Client {}", e.getMessage());
}
finally {
}
I need to close the client in the final block, but I can't because I'm getting an error (Cannot resolve symbol client).
Is there any way to close this client in the final block?
Solution
Client will be closed, cause you are using try-with-resources (when you open resourse in try(resource definition)
), which closes resource after try block automatically, you don`t need to write finally block.
Answered By - iggi