What is the basic Docker image (`FROM`) for Java Spring Download?

What is the basic Docker image ( FROM ) for Java Spring Download the application?

I am just starting with docker, and I see that FROM inside the Dockerfile can define an image for Java, for example

 FROM java:8 

If I create using Gradle (or Maven), is this the best base image to start avoiding customization later than what is common to the Gradle / Maven project?

And, of course, Spring's Download Application is just a .jar file inside the build output folder, there should be less questions about how to work with Docker (for a Java project built with standard build tools)

+6
source share
2 answers

There is good documentation on Spring-Boot integration with Docker: https://spring.io/guides/gs/spring-boot-docker/

Essentially, you define your dockerfile in src/main/docker/Dockerfile and configure docker-maven-plugin as follows:

 <build> <plugins> <plugin> <groupId>com.spotify</groupId> <artifactId>docker-maven-plugin</artifactId> <version>0.4.11</version> <configuration> <imageName>${docker.image.prefix}/${project.artifactId}</imageName> <dockerDirectory>src/main/docker</dockerDirectory> <resources> <resource> <targetPath>/</targetPath> <directory>${project.build.directory}</directory> <include>${project.build.finalName}.jar</include> </resource> </resources> </configuration> </plugin> </plugins> 

Dockerfile:

 FROM frolvlad/alpine-oraclejre8:slim VOLUME /tmp ADD gs-spring-boot-docker-0.1.0.jar app.jar RUN sh -c 'touch /app.jar' ENV JAVA_OPTS="" ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /app.jar" ] 

Note that in this FROM frolvlad/alpine-oraclejre8:slim example FROM frolvlad/alpine-oraclejre8:slim is a small-fingerprint image based on Alpine Linux.

You should also be able to use a standard Java 8 image (which is based on Debian and may have a larger area). An extensive list of available Java base images can be found here: https://github.com/docker-library/docs/tree/master/openjdk .

+7
source

I use the Fabric plugin, which uses the base docker image fabric8 / java-alpine-openjdk8-jdk: 1.2. There is no need for a Dockerfile, it is created by the plugin .

 <build> <finalName>${project.artifactId}-${project.version}</finalName> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>3.3</version> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> <plugin> <groupId>io.fabric8</groupId> <artifactId>fabric8-maven-plugin</artifactId> <version>3.2.28</version> </plugin> </plugins> </build> 

The targets are fabric8: a build for creating a docker image, and fabric8: push for pushing the registry of docker images.

 mvn clean install fabric8:build fabric8:push 
+3
source

Source: https://habr.com/ru/post/1263198/


All Articles