Maven Docker Plugin Connection refused

I am using this maven docker plugin

https://github.com/wouterd/docker-maven-plugin

My pom.xml file looks like

            <plugin>
            <groupId>net.wouterdanes.docker</groupId>
            <artifactId>docker-maven-plugin</artifactId>
            <version>5.0.0</version>
            <executions>
                <execution>
                    <id>package</id>
                    <goals>
                        <goal>build-images</goal>
                    </goals>
                    <configuration>
                        <images>
                            <image>
                                <id>cloudera</id>
                                <dockerFile>${project.basedir}/src/integration-test/docker/Dockerfile</dockerFile>
                                <artifacts>
                                    <artifact>
                                        <file>${project.build.directory}/${project.build.finalName}.jar</file>
                                    </artifact>
                                </artifacts>
                            </image>
                        </images>
                    </configuration>
                </execution>
                <execution>
                    <id>start</id>
                    <goals>
                        <goal>start-containers</goal>
                    </goals>
                    <configuration>
                        <!-- You can set forceCleanup to true to stop and remove started containers
                             at the end of the build even if the stop-containers goal is not executed
                             (useful for preventing Ctrl+C causing dangling containers) -->
                        <forceCleanup>true</forceCleanup>
                        <containers>
                            <container>
                                <id>cloudera</id>
                                <image>cloudera/quickstart</image>                                    
                                <waitForStartup>Cloudera started for</waitForStartup>
                            </container>
                        </containers>
                    </configuration>
                </execution>
                <execution>
                    <id>stop</id>
                    <goals>
                        <goal>stop-containers</goal>
                    </goals>
                </execution>
                <execution>
                    <id>verify</id>
                    <goals>
                        <goal>verify</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

when I run my build using mvn verify -e -X I get error

    ERROR] Failed to execute goal net.wouterdanes.docker:docker-maven-plugin:5.0.0:build-images (package) on project SparkIntegrationTest: Execution package of goal net.wouterdanes.docker:docker-maven-plugin:5.0.0:build-images failed: java.net.ConnectException: Connection refused -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal net.wouterdanes.docker:docker-maven-plugin:5.0.0:build-images (package) on project SparkIntegrationTest: Execution package of goal net.wouterdanes.docker:docker-maven-plugin:5.0.0:build-images failed: java.net.ConnectException: Connection refused
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.PluginExecutionException: Execution package of goal net.wouterdanes.docker:docker-maven-plugin:5.0.0:build-images failed: java.net.ConnectException: Connection refused
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:145)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
    ... 20 more
Caused by: javax.ws.rs.ProcessingException: java.net.ConnectException: Connection refused
    at org.glassfish.jersey.client.HttpUrlConnector.apply(HttpUrlConnector.java:229)
    at org.glassfish.jersey.client.ClientRuntime.invoke(ClientRuntime.java:246)
    at org.glassfish.jersey.client.JerseyInvocation$1.call(JerseyInvocation.java:667)
    at org.glassfish.jersey.client.JerseyInvocation$1.call(JerseyInvocation.java:664)
    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:424)
    at org.glassfish.jersey.client.JerseyInvocation.invoke(JerseyInvocation.java:664)
    at org.glassfish.jersey.client.JerseyInvocation$Builder.method(JerseyInvocation.java:424)
    at org.glassfish.jersey.client.JerseyInvocation$Builder.post(JerseyInvocation.java:333)
    at net.wouterdanes.docker.remoteapi.MiscService.buildImage(MiscService.java:130)
    at net.wouterdanes.docker.provider.RemoteApiBasedDockerProvider.buildImage(RemoteApiBasedDockerProvider.java:99)
    at net.wouterdanes.docker.maven.BuildImageMojo.doExecute(BuildImageMojo.java:60)
    at net.wouterdanes.docker.maven.AbstractDockerMojo.execute(AbstractDockerMojo.java:120)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
    ... 21 more
Caused by: java.net.ConnectException: Connection refused
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    at java.net.Socket.connect(Socket.java:589)
    at sun.net.NetworkClient.doConnect(NetworkClient.java:175)
    at sun.net.www.http.HttpClient.openServer(HttpClient.java:432)
    at sun.net.www.http.HttpClient.openServer(HttpClient.java:527)
    at sun.net.www.http.HttpClient.<init>(HttpClient.java:211)
    at sun.net.www.http.HttpClient.New(HttpClient.java:308)
    at sun.net.www.http.HttpClient.New(HttpClient.java:326)
    at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:1168)
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1104)
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:998)

The thing I don’t understand is “connection refused to what”? which resource is not connectable? if I knew perhaps I could have troubleshooted this.

Answer

I haven’t used that plugin but from he docs it says that it uses the docker HTTP API to talk to the deamon. By default the HTTP API is disabled (as it can be a security risk, and uses a file socket). To enable the HTTP API you’ll have to change the startup parameters of the daemon and add the parameter -H tcp://0.0.0.0:2375 (or specify an ip rather than 0.0.0.0). This is explained on the docker daemon docs and on the plugin documentation

The above applies to Linux (as docker runs natively there). On Windows or Mac you’ll be using docker machine. In those cases, you need to set 3 environment variables which you can get from running the command docker-machine env default and then run the maven command.

Leave a Reply

Your email address will not be published. Required fields are marked *