Apache连接运行Docker-client Java API时拒绝 [英] Apache Connection Refused when running Docker-client Java API

查看:2126
本文介绍了Apache连接运行Docker-client Java API时拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试安装Docker-client Remote API库( https://github.com/spotify / docker-client )进行一些图像搜索和检查图像数据(都在公共存储库中)。我有boot2docker VM下载,安装并运行。诸如Docker pull ubuntu这样的命令工作正常,但我想通过Java程序来做到这一点。我使用Eclipse IDE Egit插件来导入github项目,并从现有的Master分支创建了一个Maven / Java项目。源代码完全导入,没有报告错误。然后我尝试写一个简单的测试:

  final DockerClient docker = DefaultDockerClient.fromEnv()。build(); 
//docker.pull(\"busybox);
列表< ImageSearchResult> results = docker.searchImages(ubuntu);
for(ImageSearchResult res:results){
System.out.println(res.getName());
}

但是,当在Eclipse中运行代码时,会收到以下错误: p>

 线程main中的异常com.spotify.docker.client.DockerException:java.util.concurrent.ExecutionException:javax.ws。 rs.ProcessingException:org.apache.http.conn.HttpHostConnectException:连接到本地主机:2375 [localhost / 127.0.0.1,localhost / 0:0:0:0:0:0:0:1]失败:连接拒绝:connect 
at com.spotify.docker.client.DefaultDockerClient.propagate(DefaultDockerClient.java:1109)
at com.spotify.docker.client.DefaultDockerClient.request(DefaultDockerClient.java:1028)
在com.spotify.docker.client.DefaultDockerClient.searchImages(DefaultDockerClient.java:653)
在com.spotify.docker.client.main.Test.main(Test.java:28)

我尝试在该端口上设置一个apache服务器,但是我得到:



线程main中的异常com.spotify.docker.client.DockerRequestException:Reques t错误:GET http:// localhost:2375 / v1.12 / images / search?term = ubuntu:404
at com.spotify.docker.client.DefaultDockerClient.propagate(DefaultDockerClient.java:1100)
at com.spotify.docker.client.DefaultDockerClient.request(DefaultDockerClient.java:1028)
at com.spotify.docker.client.DefaultDockerClient.searchImages(DefaultDockerClient.java:653)
at com .spotify.docker.client.main.Test.main(Test.java:28)

任何人告诉我我应该做什么来做我的搜索/拉电话工作?这是我与Docker的第一次尝试,我已经通过文档搜索并且googled的问题,但找不到有类似问题的人。



谢谢! p>

编辑:我通过预构建的VM Boot2Docker在Windows 7中运行docker。也许在VM之外的程序无法访问Docker守护程序,如Eclipse之外的程序?



编辑:通过升级到v1.6而不是v1.5来解决它这使守护进程在Windows主机中可用。当前的问题是我所有的API调用都返回服务器响应不正确的HTTP响应

解决方案

类似的问题,我设法通过使用以下方式来解决这个问题,以构建DockerClient:

  final DockerClient docker = DefaultDockerClient .builder()
.uri(URI.create(unix:///var/run/docker.sock))
.build();

我已经得到同样的异常,但添加上述URI部分可以帮助我解决问题。
在以下问题跟踪器中提供了与上述类似的问题以及如何解决问题的更好解释。



https://github.com/spotify/docker-maven-plugin/issues/61


I am trying to install the Docker-client Remote API library ( https://github.com/spotify/docker-client ) to do some image searches and inspect image data (all in public repositories). I have the boot2docker VM downloaded, installed and running. Commands such as "Docker pull ubuntu" work fine but I would like to do this via a Java program now. I used the Eclipse IDE Egit plugin to import the github project and created a Maven/Java project from the existing Master branch. The source code is completely imported and no errors reported. I then tried writing a simple test:

    final DockerClient docker = DefaultDockerClient.fromEnv().build();
    //docker.pull("busybox");
    List<ImageSearchResult> results = docker.searchImages("ubuntu");
    for (ImageSearchResult res : results) {
        System.out.println(res.getName());
    }

However, when running the code in Eclipse I get the following error:

Exception in thread "main" com.spotify.docker.client.DockerException: java.util.concurrent.ExecutionException: javax.ws.rs.ProcessingException: org.apache.http.conn.HttpHostConnectException: Connect to localhost:2375 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused: connect
at com.spotify.docker.client.DefaultDockerClient.propagate(DefaultDockerClient.java:1109)
at com.spotify.docker.client.DefaultDockerClient.request(DefaultDockerClient.java:1028)
at com.spotify.docker.client.DefaultDockerClient.searchImages(DefaultDockerClient.java:653)
at com.spotify.docker.client.main.Test.main(Test.java:28)

I tried setting up an apache server on that port but then I get:

Exception in thread "main" com.spotify.docker.client.DockerRequestException: Request error: GET http://localhost:2375/v1.12/images/search?term=ubuntu: 404
at com.spotify.docker.client.DefaultDockerClient.propagate(DefaultDockerClient.java:1100)
at com.spotify.docker.client.DefaultDockerClient.request(DefaultDockerClient.java:1028)
at com.spotify.docker.client.DefaultDockerClient.searchImages(DefaultDockerClient.java:653)
at com.spotify.docker.client.main.Test.main(Test.java:28)

Can anyone tell me what I am supposed to do here to make my search/pull call work? This is my first try with Docker and I've searched through the documentation and googled the problem but can't find anyone with a similar problem.

Thank you!

EDIT: I am running docker in Windows 7 via the pre-built VM Boot2Docker. Maybe the Docker daemon running inside that is not accessible from programs outside of the VM such as Eclipse?

EDIT: solved it by upgrading to v1.6 instead of v1.5 which makes the daemon available in the Windows host. Current problem is that all my API calls are returning "The server failed to respond with a valid HTTP response"

解决方案

I encountered a similar issue and I managed to solve this issue by using the following way, to build up the DockerClient:

final DockerClient docker = DefaultDockerClient.builder()
                    .uri(URI.create("unix:///var/run/docker.sock"))
                    .build();

I had been getting the same exception but adding the above URI part helped me to solve the issue. A better explanation for a issue similar to the above and how to solve it has been provided in the following issue tracker.

https://github.com/spotify/docker-maven-plugin/issues/61

这篇关于Apache连接运行Docker-client Java API时拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆