码迷,mamicode.com
首页 > 编程语言 > 详细

win10环境下使用docker部署spring-boot项目

时间:2020-04-07 12:45:48      阅读:80      评论:0      收藏:0      [点我收藏+]

标签:utf-8   desc   lookup   odi   技术   pos   optional   java   web   

基本目录结构

技术图片

前置条件

  1. windows正常docker服务启动

pom插件配置

<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>2.2.1.RELEASE</version>
		<relativePath/> <!-- lookup parent from repository -->
	</parent>
	<groupId>com.sun</groupId>
	<artifactId>docker-demo</artifactId>
	<version>0.0.1</version>
	<name>docker-demo</name>
	<description>Demo project for Spring Boot</description>

	<properties>
		<java.version>1.8</java.version>
		<docker.image.prefix>springboot</docker.image.prefix>
	</properties>

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

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-devtools</artifactId>
			<scope>runtime</scope>
			<optional>true</optional>
		</dependency>
		<dependency>
			<groupId>org.projectlombok</groupId>
			<artifactId>lombok</artifactId>
			<optional>true</optional>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
			<exclusions>
				<exclusion>
					<groupId>org.junit.vintage</groupId>
					<artifactId>junit-vintage-engine</artifactId>
				</exclusion>
			</exclusions>
		</dependency>
	</dependencies>

	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>

			<plugin>
				<groupId>com.spotify</groupId>
				<artifactId>docker-maven-plugin</artifactId>
				<version>0.4.14</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>
	</build>

</project>

Dockerfile文件配置

FROM openjdk:8-jdk-alpine
VOLUME /tmp
ADD docker-demo-0.0.1.jar app.jar
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]

执行插件命令

项目路径下执行 mvn clean package docker:build命令进行打包且构建镜像
技术图片
技术图片

查看结果

技术图片

上面是利用插件进行构建镜像的方式;如果没有使用该插件可以直接将执行mvn package后生成的jar包,复制到含有Dockerfile的文件夹中,然后执行docker命令docker build -t docker-spring-demo:0.0.1 . 构建镜像

踩坑记录

  1. Dockerfile写成DockerFile后,执行失败
    2.maven中<include>${project.build.finalName}.jar</include>.jar漏写之后,执行命令后一直找不到jar包

win10环境下使用docker部署spring-boot项目

标签:utf-8   desc   lookup   odi   技术   pos   optional   java   web   

原文地址:https://www.cnblogs.com/yiweiblog/p/12652566.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!