docker化 springboot项目

Posted 博客首页

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了docker化 springboot项目相关的知识,希望对你有一定的参考价值。

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

	<modelVersion>4.0.0</modelVersion>

	<groupId>com.lnas01</groupId>
	<artifactId>docker-spring-boot</artifactId>
	<packaging>jar</packaging>
	<version>1.0.0</version>
	<name>docker-spring-boot</name>
	<description>Getting started with Spring Boot and Docker</description>
	
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.3.3.RELEASE</version>
        <relativePath/>
    </parent>

	<dependencies>
	    <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
	</dependencies>

	<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
    <!-- tag::plugin[] -->
			<plugin>
				<groupId>com.spotify</groupId>
				<artifactId>docker-maven-plugin</artifactId>
				<version>0.4.3</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>
    <!-- end::plugin[] -->
        </plugins>
	</build>

	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<docker.image.prefix>lnas01</docker.image.prefix>
		<spring.boot.version>1.3.3.RELEASE</spring.boot.version>
	</properties>
</project>

  

dockerfilesrc/main/docker/Dockerfile

 
FROM frolvlad/alpine-oraclejdk8:slim
VOLUME /tmp
ADD docker-spring-boot-1.0.0.jar app.jar
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]

  

构建镜像:

mvn package docker:build

  

运行镜像:

docker run -p 8080:8080 -t lnas01/docker-spring-boot

  

以上是关于docker化 springboot项目的主要内容,如果未能解决你的问题,请参考以下文章

创建片段而不从 java 代码实例化它

Springboot2 Vue 前后端分离 整合打包 docker镜像

体验SpringBoot(2.3)应用制作Docker镜像(官方方案)

体验SpringBoot(2.3)应用制作Docker镜像(官方方案)

Docker Compose部署Springboot+Mysql项目

如何使用Docker发布SpringBoot项目