首页 > 其他分享 >Springboot项目部署到docker

Springboot项目部署到docker

时间:2022-11-10 13:57:45浏览次数:35  
标签:Springboot service 部署 jar acl docker Dockerfile 打包

Manve项目部署到docker

第一步:将springboot项目打包

  1. Maven打包Spring Boot项目报错(repackage failed: Unable to find main class),排除寻找Main方法,一般用于被依赖的公用常量模块,解决方法如下:

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <mainClass>none</mainClass>     <!-- 取消查找本项目下的Main方法:为了解决Unable to find main class的问题 -->
                    <classifier>execute</classifier>    <!-- 为了解决依赖模块找不到此模块中的类或属性 -->
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    

  2. SpringBoot 项目打包后不加载 application.properties 配置文件,添加pom文件中的打包资源即可

    <resources>
    	<!--如果pro和xml文件放在源码java包下,也需要编译-->
    	<resource>
    		<directory>src/main/java</directory>
    		<includes>
    			<include>**/*.yml</include>
    			<include>**/*.properties</include>
    			<include>**/*.xml</include>
    		</includes>
    		<filtering>false</filtering>
    	</resource>
    	<resource>
    		<directory>src/main/resources</directory>
    		<includes>
    			<include>**/*.yml</include>
    			<include>**/*.properties</include>
    			<include>**/*.xml</include>
    		</includes>
    		<filtering>false</filtering>
    	</resource>
    </resources>
    

第二步:dockerfile打包

  1. 进入到dockerFile文件夹

    cd /root/hsc/dockerFile
    
  2. 创建Dockerfile文件

    vim Dockerfile
    
  3. 编辑Dockerfile文件

    # 拉取基础镜像
    FROM openjdk:11.0.2
    # 设置作者信息
    MAINTAINER hsc"[email protected]"
    # 把api_gateway-0.0.1-SNAPSHOT.jar添加到容器里,并重命名为api_gateway.jar
    ADD service_acl-0.0.1-SNAPSHOT.jar service_acl.jar
    # 设置端口号,此处只开放一个端口8001
    EXPOSE 8001
    # 执行命令,此处运行api_gateway.jar
    RUN bash -c 'touch /service_acl.jar'
    ENTRYPOINT ["java","-jar","service_acl.jar"]
    

第三步:制作docker镜像

#service_acl:v1.0表示你的镜像名称,可以自己输入其他的。命令后面的 . 不能省略
docker build -f Dockerfile -t service_acl:v1.0 .

标签:Springboot,service,部署,jar,acl,docker,Dockerfile,打包
From: https://www.cnblogs.com/lijl1015/p/16876792.html

相关文章