docker-maven-plugin
docker-maven-plugin copied to clipboard
Maven build with Docker plugin fails when executed via Jenkins
I installed docker locally (mac book pro) and I successfully wrote a build script in maven which creates docker containers, executes tests and then terminates the containers. Very good.
Now I used jenkins to run the same maven script on the server side. The server side is a red hat server running docker 1.10.3
But on the server side I get this error
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:224) 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:120) at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:347) at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:154) at org.jvnet.hudson.maven3.launcher.Maven32Launcher.main(Maven32Launcher.java:132) 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.launchStandard(Launcher.java:330) at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:238) at jenkins.maven3.agent.Maven32Main.launch(Maven32Main.java:186) 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 hudson.maven.Maven3Builder.call(Maven3Builder.java:136) at hudson.maven.Maven3Builder.call(Maven3Builder.java:71) at hudson.remoting.UserRequest.perform(UserRequest.java:121) at hudson.remoting.UserRequest.perform(UserRequest.java:49) at hudson.remoting.Request$2.run(Request.java:326) at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:68) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745) 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:143) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208) ... 30 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:132) ... 31 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.
(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) at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:932) at sun.net.www.protocol.http.HttpURLConnection.getOutputStream0(HttpURLConnection.java:1282) at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1257) at org.glassfish.jersey.client.HttpUrlConnector$3.getOutputStream(HttpUrlConnector.java:312) at org.glassfish.jersey.message.internal.CommittingOutputStream.commitStream(CommittingOutputStream.java:200) at org.glassfish.jersey.message.internal.CommittingOutputStream.commitStream(CommittingOutputStream.java:194) at org.glassfish.jersey.message.internal.CommittingOutputStream.write(CommittingOutputStream.java:213) at org.glassfish.jersey.message.internal.WriterInterceptorExecutor$UnCloseableOutputStream.write(WriterInterceptorExecutor.java:294) at org.glassfish.jersey.message.internal.ByteArrayProvider.writeTo(ByteArrayProvider.java:96) at org.glassfish.jersey.message.internal.ByteArrayProvider.writeTo(ByteArrayProvider.java:60) at org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor.invokeWriteTo(WriterInterceptorExecutor.java:265) at org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor.aroundWriteTo(WriterInterceptorExecutor.java:250) at org.glassfish.jersey.message.internal.WriterInterceptorExecutor.proceed(WriterInterceptorExecutor.java:162) at org.glassfish.jersey.message.internal.MessageBodyFactory.writeTo(MessageBodyFactory.java:1154) at org.glassfish.jersey.client.ClientRequest.writeEntity(ClientRequest.java:503) at org.glassfish.jersey.client.HttpUrlConnector._apply(HttpUrlConnector.java:315) at org.glassfish.jersey.client.HttpUrlConnector.apply(HttpUrlConnector.java:227) ... 46 more
This plugin communicates with the docker daemon via http. Make sure that your jenkins build runs in an environment where docker http rest api is available.
I'm running into similar problems with this. I'm using the 5.0.0 version of the plugin (well, a local 5.0.1-SNASPHOT that enables some debug statements I added), and I've exposed the 2375 port on my docker host. This host is also running a containerized version of Jenkins, and I'm using the 172.17.0.1 address for the host (this is apparently automatically created but that's what it uses in my environment). I've setup a <server> entry with with the credentials and tied it to <serverId> in my configuration.
I've gotten past the connection refused with all of that, but now I'm getting a 404 when trying to pull an image from the public docker registry.
In case anyone is curious and/or has an idea, my build is at:
http://ci.commonjava.org:8080/job/kojiji-PRs/23/console
After much googling and head-scratching, I've also synchronized my timezone in the container and setup NTP on the docker host, just to be sure. So it's not a time issue.
I've just submitted PR #117 which was enough to get docker start/stop/create working, when used with some customization of the docker environment and tweaking the Jenkins Docker container I was running. The Jenkins setup I'm using is at:
https://github.com/Commonjava/commonjava-ci-jenkins-docker
I setup a <server> entry in the settings.xml with an encrypted password (VERY important to encrypt on CI servers, since anyone with access to Jenkins admin can setup a job to run mvn help:effective-settings and recover your password). Then I used docker network create ci-network, and configured my Maven build as follows:
https://github.com/Commonjava/jhttpc/blob/master/pom.xml
Hopefully if I can get this PR merged, the information above will help others trying to run docker containers in CI.