java HttpHostConnectException:连接到localhost:2375 [localhost/127.0.0.1]失败:连接被拒绝

k4ymrczo  于 2023-05-27  发布在  Java
关注(0)|答案(3)|浏览(868)

[错误]无法在项目Bookstore上执行goal com.spotify:docker-maven-plugin:1.0.0:build(default):捕获的异常:java.util.concurrent.ExecutionException:com.spotify.docker.client.shaded.javax.ws.rs.ProcessingException:org.apache.http.conn.HttpHostConnectException:连接到localhost:2375 [localhost/127.0.0.1]失败:连接被拒绝

  • 为什么这个异常不断发生,我如何解决它,我正在从war文件构建docker镜像。*
    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] ```

更新

[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

现在我得到这个错误后关闭防火墙,怎么办?

wmtdaxz3

wmtdaxz31#

1.将DOCKER_HOST设置为env变量tcp://localhost:2375
1.根据附带的图像更改docker桌面设置。
1.重新启动Docker桌面

0s7z1bwu

0s7z1bwu2#

您应该设置DOCKER_HOST环境变量。关于docs
默认情况下,插件会尝试连接到localhost:2375上的docker。设置DOCKER_HOST环境变量以连接到其他位置。
How to define a custom docker host url?
例如,在Windows上:

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

localhost上的Docker引擎必须配置为接受端口3000上的传入连接

bvjxkvbb

bvjxkvbb3#

在我的Mac Ventura(13.1)和Docker Desktop v4.19上,我必须在高级设置部分勾选Enable default docker socket才能使其工作..

相关问题