0

I'm trying to use the Docker-Java API. Following the instruction in https://github.com/docker-java/docker-java/blob/main/docs/getting_started.md I build a DockerClientConfig and try to build a DockerHttpClient:

DockerClientConfig config = DefaultDockerClientConfig.createDefaultConfigBuilder().build();
DockerHttpClient httpClient = new ApacheDockerHttpClient.Builder()
                .dockerHost(config.getDockerHost())
                .sslConfig(config.getSSLConfig())
                .maxConnections(100)
                .connectionTimeout(Duration.ofSeconds(30))
                .responseTimeout(Duration.ofSeconds(45))
                .build();

Then the error comes out:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/hc/client5/http/ssl/TlsSocketStrategy
    at com.github.dockerjava.httpclient5.ApacheDockerHttpClient$Builder.build(ApacheDockerHttpClient.java:50)
    at com.alibaba.ais.route.monitor.rmc.service.ContainerInfoService.func(ContainerInfoService.java:24) // this refers to "build" for the DockerhttpClient
    at com.alibaba.ais.route.monitor.rmc.Application.main(Application.java:15)
Caused by: java.lang.ClassNotFoundException: org.apache.hc.client5.http.ssl.TlsSocketStrategy
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:525)

I included the dependencies in my pom.xml:

<dependency>
    <groupId>com.github.docker-java</groupId>
    <artifactId>docker-java-core</artifactId>
    <version>3.5.0</version>
</dependency>

<dependency>
    <groupId>com.github.docker-java</groupId>
    <artifactId>docker-java-transport-httpclient5</artifactId>
    <version>3.5.0</version>
</dependency>

How do I solve this problem?

1 Answer 1

0

I still don't know the cause, but if I change to use ZerodepDockerHttpClient instead of ApacheHttpClient, the error disappears.

Sign up to request clarification or add additional context in comments.

1 Comment

Please add some information to your answer if you find out the cause.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.