springboot~ build gradle project with docker

This is an article related to four knowledge points, namely java, docker, springboot and gradle. We hope to use the springboot framework in the java environment to build the project through gradle, and then deploy and run the project in the docker container !

  1. Java runtime
  2. springboot open source scaffolding
  3. The most popular project build tool for gradle
  4. Docker's most popular container product

development process

A build.gradle file

   dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")

        classpath('se.transmode.gradle:gradle-docker:1.2')
    }

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'docker'

version = '1.0.0'
jar {
    baseName = 'springdemo'
}

task buildDocker(type: Docker, dependsOn: build) {
    push = true
    applicationName = jar.baseName
    dockerfile = file('src/main/docker/Dockerfile')
    doFirst {
        copy {
            from jar
            into stageDir
        }
    }
}

2. Compile the project

docker build

Three generation mirrors

docker build buildDocker

Four running containers

docker run -p 80:8080  springdemo-1.0.0

Five-year picture

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325649948&siteId=291194637