Enterprise spring boot tutorial springboot integration docker

This article introduces how to build a docker image for the springboot program. Docker is an open source application container engine based on Go language and Apache 2.0 protocol. Docker allows developers to package their applications and dependencies into a lightweight, portable container, and then publish them to any popular Linux machine. It also enables virtualization. Containers use sandbox mechanism completely, and there is no interface between them (like iPhone apps). More importantly, the performance overhead of containers is very low. Spring Cloud large enterprise distributed microservice Cloud Architecture source code Please add 1791743380


Environmental Science:

linux environment or mac, do not use windows

jdk 8

maven 3.0


I don't know anything about docker.

Create a springboot project

Introduce the starting dependency of web and create a controller:



public class SpringbootWithDockerApplication {



    public String home() {

        return "Hello Docker World";


    public static void main(String[] args) {

        SpringApplication.run(SpringbootWithDockerApplication.class, args);



Container the springboot project

Docker has a simple dockerFile file as the layer for the specified image. Let's create a dockerFile file first:


FROM frolvlad/alpine-oraclejdk8:slim


ADD springboot-with-docker-0.0.1-SNAPSHOT.jar app.jar

RUN sh -c 'touch /app.jar'


ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /app.jar" ]

We build docker image through maven.

Add the plug-in built by docker image to the pom directory of maven
























With the maven command:

Step 1: mvn clean

Step 2: MVN package docker: built, as follows:

Step 2/6 : VOLUME /tmp

—> Running in a98be3878053

—> 8286e98b54c5

Removing intermediate container a98be3878053

Step 3/6 : ADD springboot-with-docker-0.0.1-SNAPSHOT.jar app.jar

—> c6ce13e50bbd

Removing intermediate container a303a3058869

Step 4/6 : RUN sh -c 'touch /app.jar'

—> Running in cf231afe700e

—> 9a0ec8936c00

Removing intermediate container cf231afe700e

Step 5/6 : ENV JAVA_OPTS ""

—> Running in e192597fc881

—> 2cb0d73bbdb0

Removing intermediate container e192597fc881

Step 6/6 : ENTRYPOINT sh -c java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /app.jar

—> Running in ab85f53fcdd8

—> 60fdb5c61692

Removing intermediate container ab85f53fcdd8

Successfully built 60fdb5c61692

[INFO] Built forezp/springboot-with-docker

[INFO] ------------


[INFO] ------------

[INFO] Total time: 01:45 min

[INFO] Finished at: 2017-04-19T05:37:44-07:00

[INFO] Final Memory: 19M/48M

[INFO] ------------

Keywords: Docker SpringBoot Maven Linux

Added by Jimmy_uk on Sat, 30 Nov 2019 12:59:13 +0200