我已经在windows 10上安装了virtualbox,并为docker主机创建了一个Ubuntu示例。然后在Ubuntu上安装了docker。我想使用docker-java API连接docker(我使用的是docker-java 3.0.12),代码如下:
DockerClientConfig config = DefaultDockerClientConfig.createDefaultConfigBuilder()
.withDockerHost("tcp://192.168.5.31:2375").build();
DockerClient dockerClient = DockerClientBuilder.getInstance(config).build();
CreateContainerResponse container1 =
dockerClient.createContainerCmd("tomcat:latest").withCmd("sleep", "9999") .withName("mytomcat3").exec();
dockerClient = DockerClientBuilder.getInstance().build();
dockerClient.startContainerCmd(container1.getId()).exec();
我得到了以下信息:
java.lang.RuntimeException: Library 'junixsocket-native-2.0.4.dll' not found!
at org.newsclub.net.unix.NarSystem.getLibPath(NarSystem.java:132)
at org.newsclub.net.unix.NarSystem.loadLibrary(NarSystem.java:36)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.newsclub.net.unix.NativeUnixSocket.<clinit>(NativeUnixSocket.java:35)
at org.newsclub.net.unix.AFUNIXSocket.<init>(AFUNIXSocket.java:36)
at org.newsclub.net.unix.AFUNIXSocket.newInstance(AFUNIXSocket.java:54)
at com.github.dockerjava.jaxrs.ApacheUnixSocket.<init>(ApacheUnixSocket.java:51)
at com.github.dockerjava.jaxrs.UnixConnectionSocketFactory.createSocket(UnixConnectionSocketFactory.java:66)
at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:118)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:353)
at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:380)
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184)
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:88)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:71)
at org.glassfish.jersey.apache.connector.ApacheConnector.apply(ApacheConnector.java:435)
at org.glassfish.jersey.client.ClientRuntime.invoke(ClientRuntime.java:252)
at org.glassfish.jersey.client.JerseyInvocation$1.call(JerseyInvocation.java:684)
at org.glassfish.jersey.client.JerseyInvocation$1.call(JerseyInvocation.java:681)
at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
at org.glassfish.jersey.internal.Errors.process(Errors.java:228)
at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:444)
at org.glassfish.jersey.client.JerseyInvocation.invoke(JerseyInvocation.java:681)
at org.glassfish.jersey.client.JerseyInvocation$Builder.method(JerseyInvocation.java:437)
at org.glassfish.jersey.client.JerseyInvocation$Builder.post(JerseyInvocation.java:343)
at com.github.dockerjava.jaxrs.StartContainerCmdExec.execute(StartContainerCmdExec.java:29)
at com.github.dockerjava.jaxrs.StartContainerCmdExec.execute(StartContainerCmdExec.java:12)
at com.github.dockerjava.jaxrs.AbstrSyncDockerCmdExec.exec(AbstrSyncDockerCmdExec.java:23)
at com.github.dockerjava.core.command.AbstrDockerCmd.exec(AbstrDockerCmd.java:35)
at com.github.dockerjava.core.command.StartContainerCmdImpl.exec(StartContainerCmdImpl.java:46)
at docker.MyDocker.main(MyDocker.java:53)...
我无法下载dll。你能告诉我如何解决这个问题吗?
非常感谢!
2条答案
按热度按时间sz81bmfz1#
我已经找到了一个使用另一个Java API的解决方案,即spotify/docker-client。我使用的API如下:
现在我建议你可以使用下面的代码来访问Docker。
干杯干杯干杯
toe950272#
junixsocket版本2.0.4不支持Windows。您需要升级到更高版本。
尝试将junixsocket依赖项更改为