Apache Connection Refused when running Docker-client Java API

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();
    List<ImageSearchResult> results = docker.searchImages("ubuntu");
    for (ImageSearchResult res : results) {

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/, 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”

  • Maven release plugin git credentials
  • Github authentication: how to use Github as Maven repo when repo is private
  • Eclipse GIT reindex loop plus append .gitignore
  • Fail upload jar into github with maven
  • How can I manage the deprecation of a maven repository in git?
  • Building/Waiting for parent job Latest version
  • How to include library jar in git project
  • Gradle dependencies cache in project directory
  • 3 Solutions collect form web for “Apache Connection Refused when running Docker-client Java API”

    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()

    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.


    The Java program does essentially a docker search: that can only work in an environment where the docker engine is present.

    Either in the boot2docker VM.
    Or in a full Linux host.

    I did encounter the same problem on Mac with eclipse and Docker version 1.10.3, I did search for a solution before I settled for a workaround – Using docker CLI docker-manager to create a new virtualbox and get the DOCKER_HOST and DOCKER_CERT_PATH values of that virtualbox and create a new builder.

    In my case: I have created a virtual box default2 using docker CLI command docker-machine create -d virtualbox default2

    Docker CLI

    $ docker-machine env
    export DOCKER_TLS_VERIFY="1"
    export DOCKER_HOST="tcp://"
    export DOCKER_CERT_PATH="/Users/XXXX/.docker/machine/machines/default2"
    export DOCKER_MACHINE_NAME="default2"

    Docker-client JAVA

    DockerCertificates defaultCertificates = new DockerCertificates(Paths.get("/Users/XXXX/.docker/machine/machines/default2"));    
    DockerClient docker = DefaultDockerClient.builder()
    Git Baby is a git and github fan, let's start git clone.