title: Connection refused while launching docker containers using java client
body: <p>I 'am new to docker , I want to launch docker containers using java client ,</p>
  
  <p>I tried <a href="https://github.com/docker-java/docker-java" rel="nofollow noreferrer">https://github.com/docker-java/docker-java</a> as below </p>
  
  <pre><code>package containers.launch_containers;
  
  import com.github.dockerjava.api.DockerClient;
  import com.github.dockerjava.core.DockerClientBuilder;
  
  public class StartContainers{
       DockerClient dockerClient;
  
      public StartContainers() {
          startContainers();
      }
  
      public void startContainers() {
             try {
  
                  dockerClient = DockerClientBuilder.getInstance("tcp://127.0.0.1:2375").build();
                  //starting the container of hello-world 
                  dockerClient.startContainerCmd("hello-world").exec();
  
  
      }catch(Exception ex)
             {
               ex.printStackTrace();
             }
      }
  
      public static void main(String args[])
      {
          StartContainers startContainers=new StartContainers();
      }   
  }
  </code></pre>
  
  <p>with setting the required configurations in bashrc</p>
  
  <blockquote>
    <p>export DOCKER_HOST=tcp://127.0.0.1:2375 </p>
    
    <p>export DOCKER_OPTS="-H tcp://127.0.0.1:2375 -H
    unix:///var/run/docker.sock"</p>
  </blockquote>
  
  <p>Docker Images in localhost </p>
  
  <p><a href="https://i.stack.imgur.com/p0upF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/p0upF.png" alt="dockerimages"></a></p>
  
  <p>I have got this Exception</p>
  
  <blockquote>
    <p>javax.ws.rs.ProcessingException:
    org.apache.http.conn.HttpHostConnectException: Connect to
    127.0.0.1:2375 [/127.0.0.1] failed: Connection refused (Connection refused)   at
    org.glassfish.jersey.apache.connector.ApacheConnector.apply(ApacheConnector.java:481)
      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
    containers.launch_containers.StartContainers.startContainers(StartContainers.java:18)
      at
    containers.launch_containers.StartContainers.(StartContainers.java:10)
      at
    containers.launch_containers.StartContainers.main(StartContainers.java:29)</p>
  </blockquote>