未能执行目标 com.spotify:docker-maven-plugin:0.4.3:build 捕获异常:HttpHostConnectException: Connect to localho

Posted

技术标签:

【中文标题】未能执行目标 com.spotify:docker-maven-plugin:0.4.3:build 捕获异常:HttpHostConnectException: Connect to localhost:2375【英文标题】:Failed to execute goal com.spotify:docker-maven-plugin:0.4.3:build Exception caught: HttpHostConnectException: Connect to localhost:2375 【发布时间】:2018-04-29 11:48:33 【问题描述】:

使用docker部署Spring Cloud项目,pom.xml中的一些代码:

<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <!-- tag::plugin[] -->
            <plugin>
                <groupId>com.spotify</groupId>
                <artifactId>docker-maven-plugin</artifactId>
                <version>0.4.3</version>
                <configuration>
                    <imageName>$docker.image.prefix/$project.artifactId</imageName>
                    <dockerDirectory>$project.basedir</dockerDirectory>
                    <resources>
                        <resource>
                            <targetPath>/</targetPath>
                            <directory>$project.build.directory</directory>
                            <include>$project.build.finalName.jar</include>
                        </resource>
                    </resources>
                </configuration>
            </plugin>
            <!-- end::plugin[] -->

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <skipTests>true</skipTests>
                </configuration>
            </plugin>
        </plugins>
    </build>

当我运行命令时:mvn package docker:build,它会抛出错误:

[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.spotify:docker-maven-plugin:0.4.3:build (default) on project users-microservice: 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, localhost/0:0:0:0:0:0:0:1] failed: Connection refused -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command

为什么会连接到 localhost:2375?任何想法,我将不胜感激!

【问题讨论】:

localhost:2375 上是否有任何运行。容器本地接口内的localhost 指的是容器,如果您希望连接到容器主机上的:2375,则需要使用主机IP。 @stacksonstacks,在 docker 内部,我没有为端口分配任何服务:2375 【参考方案1】:

请将您的docker-maven-plugin 的版本从 0.4.3 更新到 1.0.0

<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <!-- tag::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>$project.basedir</dockerDirectory>
                    <resources>
                        <resource>
                            <targetPath>/</targetPath>
                            <directory>$project.build.directory</directory>
                            <include>$project.build.finalName.jar</include>
                        </resource>
                    </resources>
                </configuration>
            </plugin>
            <!-- end::plugin[] -->

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <skipTests>true</skipTests>
                </configuration>
            </plugin>
        </plugins>
    </build>

【讨论】:

@HerilMuratovic 太好了!

以上是关于未能执行目标 com.spotify:docker-maven-plugin:0.4.3:build 捕获异常:HttpHostConnectException: Connect to localho的主要内容,如果未能解决你的问题,请参考以下文章

如何配置 com.spotify.dockerfile-maven-plugin 在 Docker Toolbox 上运行?

com.spotify.docker.client.DockerRequestException:请求错误:删除 unix://localhost:80/v1.12/containers/...:40

docker maven 出错:Failed to execute goal com.spotify:docker-maven-plugin:...: Request error: POST http

Failed to execute goal com.spotify:docker-maven-plugin:1.0.0:build (build-image) on project training

未能执行目标 org.springframework

未能在 GitLab CI 管道中执行目标