Skip to main content

Docker Maven Plugin for Spring Applications


1. Add the following plugin in your pom.xml:

  <plugin>
              <groupId>com.spotify</groupId>
              <artifactId>docker-maven-plugin</artifactId>
              <version>0.4.13</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>build</goal>
                        </goals>
                        <phase>package</phase>
                    </execution>
                </executions>
              <configuration>
                <imageName>testrespository/${project.artifactId}</imageName>
                <baseImage>frolvlad/alpine-oraclejdk8:slim</baseImage>
                <entryPoint>["java", "-Dspring.profiles.active=local", "-DCCP_CONFIG_FILE=configCCP.xml", "-jar", "/${project.build.finalName}.jar"]</entryPoint>
                <!-- copy the service's jar file from target into the root directory of the image -->
                <resources>
                   <resource>
                     <targetPath>/</targetPath>
                     <directory>${project.build.directory}</directory>
                     <include>${project.build.finalName}.jar</include>
                   </resource>
                </resources>
              </configuration>
            </plugin>
   
Please note that artifactId should be smallcase as dockers cannot be created with uppercase letters.

2. Now, we create a volume for our Jenkins docker using the following command:

docker create -v /var/jenkins_home --name jenkins-dv jenkins


3 . Then we start a jenkins in docker :
docker run -d -p 8080:8080 --volumes-from jenkins-dv --name myjenkins2 jenkins

4. Then we enable Docker to listen on port run the following commands to start a socat docker:

docker run -p 2375:2375 -v /var/run/docker.sock:/var/run/docker.sock codenvy/socat -d -d TCP-L:2375,fork UNIX:/var/run/docker.sock


5. Go to manage plugins and select docker plugin add the following config to listen on:

127.0.0.1:2375

6. Now Create a Maven Job in Jenkins and build the code.

Comments