- Build a Jar - /target/hello-world-rest-api.jar
- Setup the Prerequisites for Running the JAR - openjdk:8-jdk-alpine
- Copy the jar
- Run the jar
- docker run -dit openjdk:8-jdk-alpine
- docker container exec naughty_knuth ls /tmp
- docker container cp target/hello-world-rest-api.jar naughty_knuth:/tmp
- docker container exec naughty_knuth ls /tmp
- docker container commit naughty_knuth in28min/hello-world-rest-api:manual1
- docker run in28min/hello-world-rest-api:manual1
- docker container ls
- docker container commit --change='CMD ["java","-jar","/tmp/hello-world-rest-api.jar"]' naughty_knuth in28min/hello-world-rest-api:manual2
- docker run -p 8080:8080 in28min/hello-world-rest-api:manual2
Hariharank12 iterm console commands
- docker build -t hariharank12/hello-world-rest-api:manual1 .
- docker run -p 8080:8080 hariharank12/hello-world-rest-api:manual1
- docker push hariharank12/hello-world-rest-api:manual1
- docker pull hariharank12/hello-world-rest-api:manual1
Run com.in28minutes.rest.webservices.restfulwebservices.RestfulWebServicesApplication as a Java Application.
Hello World
{"message":"Hello World"}
{"message":"Hello World, in28minutes"}
FROM openjdk:8-jdk-alpine
EXPOSE 8080
ADD target/hello-world-rest-api.jar hello-world-rest-api.jar
ENTRYPOINT ["sh", "-c", "java -jar /hello-world-rest-api.jar"]
FROM openjdk:8-jdk-alpine
ARG DEPENDENCY=target/dependency
COPY ${DEPENDENCY}/BOOT-INF/lib /app/lib
COPY ${DEPENDENCY}/META-INF /app/META-INF
COPY ${DEPENDENCY}/BOOT-INF/classes /app
ENTRYPOINT ["java","-cp","app:app/lib/*","com.in28minutes.rest.webservices.restfulwebservices.RestfulWebServicesApplication"]
- From Spotify
- https://github.com/spotify/dockerfile-maven
<plugin>
<groupId>com.spotify</groupId>
<artifactId>dockerfile-maven-plugin</artifactId>
<version>1.4.10</version>
<executions>
<execution>
<id>default</id>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
<configuration>
<repository>in28min/${project.name}</repository>
<tag>${project.version}</tag>
<skipDockerInfo>true</skipDockerInfo>
</configuration>
</plugin>
-
https://github.com/GoogleContainerTools/jib/tree/master/jib-maven-plugin#quickstart
-
https://github.com/GoogleContainerTools/jib/blob/master/docs/faq.md
- https://github.com/GooleContainerTools/jib/blob/master/docs/faq.md#why-is-my-image-created-48-years-ago
- GoogleContainerTools/jib#413
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
<version>1.6.1</version>
<configuration>
<container>
<creationTime>USE_CURRENT_TIMESTAMP</creationTime>
</container>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>dockerBuild</goal>
</goals>
</execution>
</executions>
</plugin>
<configuration>
<from>
<image>openjdk:alpine</image>
</from>
<to>
<image>in28min/${project.name}</image>
<tags>
<tag>${project.version}</tag>
<tag>latest</tag>
</tags>
</to>
<container>
<jvmFlags>
<jvmFlag>-Xms512m</jvmFlag>
</jvmFlags>
<mainClass>com.in28minutes.rest.webservices.restfulwebservices.RestfulWebServicesApplication</mainClass>
<ports>
<port>8100</port>
</ports>
</container>
</configuration>
- https://dmp.fabric8.io/
- Remove Spotify Maven and JIB Plugins. Add the plugin shown below and configure property for jar file.
Supports
- Dockerfile
- Defining Dockerfile contents in POM XML.
<!-- To build the image - "mvn clean package" -->
<!-- Successfully tagged webservices/01-hello-world-rest-api -->
<!-- docker run -p 8080:8080 webservices/01-hello-world-rest-api -->
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.26.0</version>
<executions>
<execution>
<id>docker-build</id>
<phase>package</phase>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
</plugin>
<properties>
...
<jar>${project.build.directory}/${project.build.finalName}.jar</jar>
</properties>
<!-- To build the image - "mvn clean package" -->
<!-- TAG - 01-hello-world-rest-api:latest -->
<!-- docker run -p 8080:8080 01-hello-world-rest-api:latest -->
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.26.0</version>
<extensions>true</extensions>
<configuration>
<verbose>true</verbose>
<images>
<image>
<name>${project.artifactId}</name>
<build>
<from>java:8-jdk-alpine</from>
<entryPoint>
<exec>
<args>java</args>
<args>-jar</args>
<args>/maven/${project.build.finalName}.jar</args>
</exec>
</entryPoint>
<assembly>
<descriptorRef>artifact</descriptorRef>
</assembly>
</build>
</image>
</images>
</configuration>
<executions>
<execution>
<id>docker-build</id>
<phase>package</phase>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack</id>
<phase>package</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
---------------
FAT JAR
---------------
JDK
---------------
---------------
CLASSES
---------------
DEPENDENCIES
---------------
JDK
---------------