docker部署本地springboot项目

官网:https://spring.io/guides/gs/spring-boot-docker/

参考文档:https://my.oschina.net/AmosWang/blog/2088358

阿里云docker信息:https://cr.console.aliyun.com/cn-hangzhou/instances/repositories

1.在项目的pom文件中添加:

            
                com.spotify
                dockerfile-maven-plugin
                1.3.6
                
                    ${docker.image.prefix}/${project.artifactId} 
                    
                    
                        target/${project.build.finalName}.jar
                    
                
            




        1.8
        pheony

在项目目录下添加Dockerfile文件

FROM openjdk:8-jdk-alpine
VOLUME /tmp
ARG JAR_FILE
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-jar","/app.jar"]

2.项目打包

idea直接右边栏install即可或mvn install打包,生成文件在target目录下

3.本地安装docker 打开shell在项目目录下运行:mvn clean package docker:build  

  错误:No plugin found for prefix 'docker' in the current project and in the plugin groups.

            修改 maven 的配置文件 settings.xml


    com.spotify

错误:Must specify baseImage if dockerDirectory

          使用mvn clean package dockerfile:build

docker部署本地springboot项目_第1张图片

 

 4.本地镜像上传仓库,服务器上docker拉取

 https://cr.console.aliyun.com/repository/cn-hangzhou/sycamore/sycamore/details

参照模板,此案例命令:

本地镜像上传
docker login --username=darksinco registry.cn-hangzhou.aliyuncs.com

docker tag 854bcdabbe68 house

docker tag 854bcdabbe68 registry.cn-hangzhou.aliyuncs.com/sycamore/sycamore:house

docker push registry.cn-hangzhou.aliyuncs.com/sycamore/sycamore:house

服务器端拉取镜像
docker login --username=darksinco registry.cn-hangzhou.aliyuncs.com

docker pull registry.cn-hangzhou.aliyuncs.com/sycamore/sycamore:house

5.服务器运行项目

docker run -p 8090:8090 -t registry.cn-hangzhou.aliyuncs.com/sycamore/sycamore:house

http://47.96.103.135:8090/swagger-ui.html可访问

转载于:https://www.cnblogs.com/sycamore0802/p/11465926.html

你可能感兴趣的:(docker部署本地springboot项目)