HttpHostConnectException: Connect to localhost:2375 [localhost/127.0.0.1] failed: Connection refused
Asked Answered
W

4

9

[ERROR] Failed to execute goal com.spotify:docker-maven-plugin:1.0.0:build (default) on project Bookstore: Exception caught: java.util.concurrent.ExecutionException: com.spotify.docker.client.shaded.javax.ws.rs.ProcessingException: org.apache.http.conn.HttpHostConnectException: Connect to localhost:2375 [localhost/127.0.0.1] failed: Connection refused

Why is this Exception Keep Occurring and how can i resolve it , i am building docker image from war file.

pom.xml

<modelVersion>4.0.0</modelVersion>
<groupId>net.codejava.javaee.bookstore</groupId>
<artifactId>Bookstore</artifactId>
<version>1.2.1</version>
<packaging>war</packaging>

 <properties>
 <docker.image.prefix>alesblaze</docker.image.prefix>
 </properties>

 <dependencies>
     <dependency>
         <groupId>javax.servlet</groupId>
         <artifactId>javax.servlet-api</artifactId>
         <version>3.1.0</version>
         <scope>provided</scope>
     </dependency>
     <dependency>
         <groupId>javax.servlet.jsp</groupId>
         <artifactId>javax.servlet.jsp-api</artifactId>
         <version>2.3.1</version>
         <scope>provided</scope>
     </dependency>
     <dependency>
         <groupId>jstl</groupId>
         <artifactId>jstl</artifactId>
         <version>1.2</version>
     </dependency>
     <dependency>
         <groupId>mysql</groupId>
         <artifactId>mysql-connector-java</artifactId>
         <version>5.1.30</version>
     </dependency>
 </dependencies>  

<build>
 <sourceDirectory>src</sourceDirectory>
 <plugins>
   <plugin>
     <artifactId>maven-compiler-plugin</artifactId>
     <version>3.5.1</version>
     <configuration>
       <source>1.8</source>
       <target>1.8</target>
     </configuration>
   </plugin>
   <plugin>
     <artifactId>maven-war-plugin</artifactId>
     <version>2.6</version>
     <configuration>
     <finalName>BookStore</finalName>
       <warSourceDirectory>WebContent</warSourceDirectory>
       <failOnMissingWebXml>false</failOnMissingWebXml>
     </configuration>
   </plugin>

   <plugin>
 <groupId>com.spotify</groupId>
 <artifactId>docker-maven-plugin</artifactId>
 <version>1.0.0</version>
 <configuration>
 <imageName>${docker.image.prefix}/${project.artifactId}</imageName>
 <dockerDirectory>Docker</dockerDirectory>
 <dockerHost>https://localhost:3000</dockerHost>
 <forceTags>true</forceTags>
 <imageTags>
 <imageTag>${project.version}</imageTag>
 <imageTag>latest</imageTag>
 </imageTags>
 <serverId>docker-hub</serverId>
 <registryUrl>https://hub.docker.com/</registryUrl>
 <resources>
 <resource>
 <targetPath>/</targetPath>
 <directory>${project.build.directory}</directory>
 <include>${project.build.finalName}.war</include>
 </resource>
 </resources>
 </configuration>
 <executions>
 <execution>
 <phase>package</phase>
 <goals>
 <goal>build</goal>
 </goals>
 </execution>
 </executions>
</plugin>

 </plugins>
</build>
</project>

DockerFile


DockerFile
``` FROM tomcat:8.5-alpine
VOLUEME /volume/mysql/
COPY /target/BookStore.war /usr/local/tomcat/webapps/app.war
RUN sh -c 'touch /usr/local/tomcat/webapps/app.war'
d
ENTRYPOINT ["sh", "-c" , "java -Djava.security.edg=file:/dev/./urandom -jar /usr/local/tomcat/webapps/app.war] ```

UPDATE

[ERROR] Failed to execute goal com.spotify:docker-maven-plugin:1.0.0:build (default) on project Bookstore: Exception caught: Timeout: GET https://localhost:2375/version: com.spotify.docker.client.shaded.javax.ws.rs.ProcessingException: org.apache.http.conn.ConnectTimeoutException: Connect to localhost:2375 [localhost/127.0.0.1] failed: connect timed out 

now i am getting this error after turning off the firewall , what to do?

Wellintentioned answered 20/9, 2019 at 9:47 Comment(2)
It is unclear, where exactly are you providing the port 2375.Rustproof
i am providing this port on my own machine (viz localhost)Wellintentioned
C
25
  1. set DOCKER_HOST into env variables as tcp://localhost:2375

  2. change docker desktop settings , as per the image attached.

  3. restart the docker desktop

enter image description here

Cydnus answered 18/8, 2020 at 0:17 Comment(1)
just check the expose daemon setting as shown by @Sarang... and restart the docker... this worked for me. No need of setting DOCKER_HOST.Cassaba
O
5

You should set the DOCKER_HOST environment variable. From the docs:

By default the plugin will try to connect to docker on localhost:2375. Set the DOCKER_HOST environment variable to connect elsewhere.

See as well How to define a custom docker host url?

For example on Windows:

set DOCKER_HOST=tcp://localhost:3000& mvn clean install

The Docker Engine on localhost must be configured to accept incoming connections on port 3000

Ornamented answered 20/9, 2019 at 12:14 Comment(2)
i am Sorry to say this but can you tell me , where should i define it in my system as i new to it , i am confused.Wellintentioned
You didn't provide any specifics about your system configuration. If you need to enable the remote API see How do I enable the remote API for dockerd @ArjunSharmaOrnamented
K
2

On my Mac Ventura (13.1) and Docker Desktop v4.19, I had to tick Enable default docker socket in the advanced setting section to make it work..enter image description  here

Kenwee answered 25/5, 2023 at 16:4 Comment(1)
Updated docker desktop for the first time in a year or two and ran into this issue while using com.bmuschko.docker-java-application for gradle. This did it for me.Orbadiah
D
1

enter image description here

Open the docker desktop settings and enable the highlighted option shown in image. It will fix the issue

Diseased answered 12/11, 2023 at 8:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.