spotify / docker-maven-plugin

INACTIVE: A maven plugin for Docker
Apache License 2.0
2.67k stars 575 forks source link

Running Jenkins+Maven+this plugin in Docker container #278

Closed brightzheng100 closed 8 years ago

brightzheng100 commented 8 years ago

Description

I'm running Jenkins+Maven with this plugin in a customized Docker image. But I got "Host name may not be null" exception while running the Maven build job.

So I docker-entered into the container and switched to the Jenkins workspace to run commands directly. All went well, as below:

root@a71ce8fcdaa6:~# cd /var/jenkins_home/workspace/springboot-jersey-swagger/
root@a71ce8fcdaa6:/var/jenkins_home/workspace/springboot-jersey-swagger# ls
LICENSE  README.md  docker  pom.xml  src  target
root@a71ce8fcdaa6:/var/jenkins_home/workspace/springboot-jersey-swagger# /opt/maven/bin/mvn docker:build
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building springboot-jersey-swagger-docker 1.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- docker-maven-plugin:0.4.12:build (default-cli) @ springboot-jersey-swagger ---
[INFO] Copying /var/jenkins_home/workspace/springboot-jersey-swagger/target/springboot-jersey-swagger-1.0.0-SNAPSHOT.jar -> /var/jenkins_home/workspace/springboot-jersey-swagger/target/docker/springboot-jersey-swagger-1.0.0-SNAPSHOT.jar
[INFO] Building image 192.168.56.118:5000/devops/springboot-jersey-swagger
Step 1 : FROM frolvlad/alpine-oraclejdk8:slim
 ---> f8103909759b
Step 2 : ADD /springboot-jersey-swagger-1.0.0-SNAPSHOT.jar //
 ---> d1333330b401
Removing intermediate container 31b44c700072
Step 3 : ENTRYPOINT java -jar /springboot-jersey-swagger-1.0.0-SNAPSHOT.jar
 ---> Running in 16e31d7bbe2b
 ---> eeb7c548fef7
Removing intermediate container 16e31d7bbe2b
Successfully built eeb7c548fef7
[INFO] Built 192.168.56.118:5000/devops/springboot-jersey-swagger
[INFO] Tagging 192.168.56.118:5000/devops/springboot-jersey-swagger with 1.0.0-SNAPSHOT
[INFO] Tagging 192.168.56.118:5000/devops/springboot-jersey-swagger with latest
[INFO] Pushing 192.168.56.118:5000/devops/springboot-jersey-swagger
The push refers to a repository [192.168.56.118:5000/devops/springboot-jersey-swagger]
d46e3813a155: Preparing
d46e3813a155: Waiting
58f7b9930e4f: Preparing
58f7b9930e4f: Waiting
d46e3813a155: Image successfully pushed
a27c88827076: Image successfully pushed
58f7b9930e4f: Image successfully pushed
9007f5987db3: Image successfully pushed
Pushing tag for rev [eeb7c548fef7] on {http://192.168.56.118:5000/v1/repositories/devops/springboot-jersey-swagger/tags/1.0.0-SNAPSHOT}
Pushing tag for rev [eeb7c548fef7] on {http://192.168.56.118:5000/v1/repositories/devops/springboot-jersey-swagger/tags/latest}
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:09 min
[INFO] Finished at: 2016-10-03T03:56:43+00:00
[INFO] Final Memory: 16M/46M
[INFO] ------------------------------------------------------------------------

How to reproduce

pom.xml:

<plugin>
                <groupId>com.spotify</groupId>
                <artifactId>docker-maven-plugin</artifactId>
                <version>0.4.12</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>build</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <baseImage>frolvlad/alpine-oraclejdk8:slim</baseImage>
                    <imageName>${docker.registry}/devops/${project.artifactId}</imageName>
                    <pushImage>true</pushImage>
                    <entryPoint>["java", "-jar", "/${project.build.finalName}.jar"]</entryPoint>

                    <resources>
                       <resource>
                         <targetPath>/</targetPath>
                         <directory>${project.build.directory}</directory>
                         <include>${project.build.finalName}.jar</include>
                       </resource>
                    </resources>

                    <forceTags>true</forceTags>
                    <imageTags>
                       <imageTag>${project.version}</imageTag>
                       <imageTag>latest</imageTag>
                    </imageTags>
                </configuration>
            </plugin>

Maven build goals in Jenkins: -X package docker:build

What do you expect

An image should be built and stored in local Docker repository which would be pushed to private Docker Registry later on (e.g. by using goals of "-X package docker:build -DpushImage")

Software:

$ docker --version Docker version 1.11.0, build 4dc5990

com.spotify docker-maven-plugin 0.4.12

$ mvn --version Apache Maven 3.3.3 (7994120775791599e205a5524ec3e0dfe41d4a06; 2015-04-22T19:57:37+08:00) Maven home: /opt/maven Java version: 1.8.0_102, vendor: Oracle Corporation Java home: /opt/jdk/jdk1.8.0_102/jre Default locale: en_SG, platform encoding: UTF-8 OS name: "linux", version: "3.16.0-30-generic", arch: "amd64", family: "unix"

Full backtrace

...
[DEBUG] Writing Dockerfile:
FROM frolvlad/alpine-oraclejdk8:slim
ADD /springboot-jersey-swagger-1.0.0-SNAPSHOT.jar //
ENTRYPOINT ["java", "-jar", "/springboot-jersey-swagger-1.0.0-SNAPSHOT.jar"]
[INFO] Building image 192.168.56.118:5000/devops/springboot-jersey-swagger
[DEBUG] Auth Config null

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 18.752 s
[INFO] Finished at: 2016-10-03T03:53:39+00:00
[INFO] Final Memory: 26M/63M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.spotify:docker-maven-plugin:0.4.12:build (default) on project springboot-jersey-swagger: Exception caught: java.util.concurrent.ExecutionException: com.spotify.docker.client.shaded.javax.ws.rs.ProcessingException: java.lang.IllegalArgumentException: Host name may not be null -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal com.spotify:docker-maven-plugin:0.4.12:build (default) on project springboot-jersey-swagger: Exception caught
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:216)
    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:862)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:286)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:197)
    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:498)
    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.MojoExecutionException: Exception caught
    at com.spotify.docker.AbstractDockerMojo.execute(AbstractDockerMojo.java:141)
    at com.spotify.docker.BuildMojo.execute(BuildMojo.java:86)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
    ... 20 more
Caused by: com.spotify.docker.client.exceptions.DockerException: java.util.concurrent.ExecutionException: com.spotify.docker.client.shaded.javax.ws.rs.ProcessingException: java.lang.IllegalArgumentException: Host name may not be null
    at com.spotify.docker.client.DefaultDockerClient.propagate(DefaultDockerClient.java:1608)
    at com.spotify.docker.client.DefaultDockerClient.request(DefaultDockerClient.java:1539)
    at com.spotify.docker.client.DefaultDockerClient.version(DefaultDockerClient.java:393)
    at com.spotify.docker.client.DefaultDockerClient.authRegistryHeader(DefaultDockerClient.java:1647)
    at com.spotify.docker.client.DefaultDockerClient.build(DefaultDockerClient.java:1148)
    at com.spotify.docker.client.DefaultDockerClient.build(DefaultDockerClient.java:1107)
    at com.spotify.docker.BuildMojo.buildImage(BuildMojo.java:567)
    at com.spotify.docker.BuildMojo.execute(BuildMojo.java:351)
    at com.spotify.docker.AbstractDockerMojo.execute(AbstractDockerMojo.java:139)
    ... 23 more
Caused by: java.util.concurrent.ExecutionException: com.spotify.docker.client.shaded.javax.ws.rs.ProcessingException: java.lang.IllegalArgumentException: Host name may not be null
    at jersey.repackaged.com.google.common.util.concurrent.AbstractFuture$Sync.getValue(AbstractFuture.java:299)
    at jersey.repackaged.com.google.common.util.concurrent.AbstractFuture$Sync.get(AbstractFuture.java:286)
    at jersey.repackaged.com.google.common.util.concurrent.AbstractFuture.get(AbstractFuture.java:116)
    at com.spotify.docker.client.DefaultDockerClient.request(DefaultDockerClient.java:1537)
    ... 30 more
Caused by: com.spotify.docker.client.shaded.javax.ws.rs.ProcessingException: java.lang.IllegalArgumentException: Host name may not be null
    at org.glassfish.jersey.apache.connector.ApacheConnector.apply(ApacheConnector.java:481)
    at org.glassfish.jersey.apache.connector.ApacheConnector$1.run(ApacheConnector.java:491)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at jersey.repackaged.com.google.common.util.concurrent.MoreExecutors$DirectExecutorService.execute(MoreExecutors.java:299)
    at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:112)
    at jersey.repackaged.com.google.common.util.concurrent.AbstractListeningExecutorService.submit(AbstractListeningExecutorService.java:50)
    at jersey.repackaged.com.google.common.util.concurrent.AbstractListeningExecutorService.submit(AbstractListeningExecutorService.java:37)
    at org.glassfish.jersey.apache.connector.ApacheConnector.apply(ApacheConnector.java:487)
    at org.glassfish.jersey.client.ClientRuntime$2.run(ClientRuntime.java:177)
    at org.glassfish.jersey.internal.Errors$1.call(Errors.java:271)
    at org.glassfish.jersey.internal.Errors$1.call(Errors.java:267)
    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:267)
    at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:340)
    at org.glassfish.jersey.client.ClientRuntime$3.run(ClientRuntime.java:209)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    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: java.lang.IllegalArgumentException: Host name may not be null
    at org.apache.http.util.Args.containsNoBlanks(Args.java:81)
    at org.apache.http.HttpHost.<init>(HttpHost.java:80)
    at org.glassfish.jersey.apache.connector.ApacheConnector.getHost(ApacheConnector.java:514)
    at org.glassfish.jersey.apache.connector.ApacheConnector.apply(ApacheConnector.java:435)
    ... 21 more
brightzheng100 commented 8 years ago

Well, I finally figured it out by some more retries.

The key points could be summarized as below:

  1. In /etc/default/docker configuration file of my Ubuntu box: DOCKER_OPTS="--insecure-registry 192.168.56.118:5000 -H tcp://0.0.0.0:4243 -H unix:///var/run/docker.sock"
  2. In pom.xml, the dockerHost must be added: <dockerHost>http://192.168.56.118:4243</dockerHost>

For those who are still struggling on similar issues.

mattnworb commented 8 years ago

Sounds like the root issue is that the plugin did not know how to communicate with your docker daemon as DOCKER_HOST environment variable or <dockerHost> was not set. I don't think you needed to add more interfaces/ports for the docker daemon to listen to in order to accomplish that.

Also, be careful about exposing the docker daemon port publicly.

brightzheng100 commented 8 years ago

Anyway, should we make it documented on the mandatory setting of <dockerHost>?

mattnworb commented 8 years ago

@brightzheng100 I believe it already is: https://github.com/spotify/docker-maven-plugin#setup

brightzheng100 commented 8 years ago

@mattnworb thanks for pointing that out but based on my experiment this info sounds NOT sufficient.

Please correct me if I'm wrong as I verified it again but failed:

Then I got "Host name may not be null" error again, as below:

[INFO] Building image 192.168.56.118:5000/devops/springboot-jersey-swagger

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 30.134 s
[INFO] Finished at: 2016-10-05T03:21:20+00:00
[INFO] Final Memory: 38M/91M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.spotify:docker-maven-plugin:0.4.13:build (default) on project springboot-jersey-swagger: Exception caught: java.util.concurrent.ExecutionException: com.spotify.docker.client.shaded.javax.ws.rs.ProcessingException: java.lang.IllegalArgumentException: Host name may not be null -> [Help 1]
mattnworb commented 8 years ago

DOCKER_HOST=tcp:192.168.56.118:4243 looks to be incorrectly formatted - I think you would want DOCKER_HOST=tcp://192.168.56.118:4243

brightzheng100 commented 8 years ago

You're right, my bad. I tried below approaches, either of which could work fine:

Thanks for your prompt support. You and your team are doing a really good job!