Spring Boot项目打包Docker镜像
Spring Boot项目打包Docker镜像
- 1.编写 Dockerfile 文件
- 2.加入 spring boot 根路径, 进行 mvn package 打包
- 3.打包上传项目并解压
- 4.进入 xiaotong_receive_data_web 项目目录执行打包命令、查看镜像、运行容器、查看容器、根据容器ID导出镜像文件 xiaotong_receive_data_web.tar
- 5.镜像上传部署服务器,导入镜像运行容器
1.编写 Dockerfile 文件
FROM openjdk:8-jdk-alpine
ARG JAR_FILE=target/xiaotong_receive_data_service-0.0.1-SNAPSHOT.jar
COPY ${JAR_FILE} xiaotong_receive_data_service-0.0.1-SNAPSHOT.jar
ENTRYPOINT ["java","-jar","/xiaotong_receive_data_service-0.0.1-SNAPSHOT.jar"]
2.加入 spring boot 根路径, 进行 mvn package 打包
3.打包上传项目并解压
drwxr-xr-x 4 root root 4096 Mar 11 21:14 xiaotong_receive_data_service
-rw-r--r-- 1 root root 64181817 Mar 11 20:21 xiaotong_receive_data_service.zip
drwxr-xr-x 5 root root 4096 Mar 11 22:21 xiaotong_receive_data_web
-rw-r--r-- 1 root root 44638431 Mar 11 20:21 xiaotong_receive_data_web.zip
4.进入 xiaotong_receive_data_web 项目目录执行打包命令、查看镜像、运行容器、查看容器、根据容器ID导出镜像文件 xiaotong_receive_data_web.tar
[root@rensun /]# cd xiaotong_receive_data_web
[root@rensun xiaotong_receive_data_web]# ll
total 36
-rw-r--r-- 1 root root 230 Mar 11 19:55 Dockerfile
drwxr-xr-x 2 root root 4096 Mar 4 11:22 logs
-rw-r--r-- 1 root root 1790 Mar 9 01:52 pom.xml
drwxr-xr-x 4 root root 4096 Jan 14 15:23 src
drwxr-xr-x 8 root root 4096 Mar 11 20:18 target
-rw-r--r-- 1 root root 14013 Mar 9 01:53 xiaotong_receive_data_web.iml
[root@rensun xiaotong_receive_data_web]# docker build -t docker.io/receive-data.io:xiaotong_receive_data_web .
Sending build context to Docker daemon 50.7 MB
Step 1/4 : FROM openjdk:8-jdk-alpine---> a3562aa0b991
Step 2/4 : ARG JAR_FILE=target/xiaotong_receive_data_web-0.0.1-SNAPSHOT.jar---> Using cache---> 76283f52d6e7
Step 3/4 : COPY ${JAR_FILE} xiaotong_receive_data_web-0.0.1-SNAPSHOT.jar---> Using cache---> 4364a9bae961
Step 4/4 : ENTRYPOINT java -jar /xiaotong_receive_data_web-0.0.1-SNAPSHOT.jar---> Using cache---> deb721008ea6
Successfully built deb721008ea6
[root@rensun xiaotong_receive_data_web]# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/receive-data.io xiaotong_receive_data_service 26b876d48521 About an hour ago 176 MB
docker.io/receive-data.io xiaotong_receive_data_web deb721008ea6 About an hour ago 155 MB
docker.io/portainer/portainer latest 62771b0b9b09 7 months ago 79.1 MB
docker.io/openjdk 8-jdk-alpine a3562aa0b991 22 months ago 105 MB
[root@rensun xiaotong_receive_data_web]# docker run docker.io/receive-data.io:xiaotong_receive_data_web. ____ _ __ _ _/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \\\/ ___)| |_)| | | | | || (_| | ) ) ) )' |____| .__|_| |_|_| |_\__, | / / / /=========|_|==============|___/=/_/_/_/:: Spring Boot :: (v2.2.0.RELEASE)2021-03-11 14:31:01.937 -- [main] INFO c.x.r.d.XiaotongReceiveDataWebApplication.logStarting - Starting XiaotongReceiveDataWebApplication v0.0.1-SNAPSHOT on 3f62c734a446 with PID 1 (/xiaotong_receive_data_web-0.0.1-SNAPSHOT.jar started by root in /)
2021-03-11 14:31:01.964 -- [main] INFO c.x.r.d.XiaotongReceiveDataWebApplication.logStartupProfileInfo - No active profile set, falling back to default profiles: default
2021-03-11 14:31:04.561 -- [main] INFO o.s.b.w.e.tomcat.TomcatWebServer.initialize - Tomcat initialized with port(s): 2021 (http)
2021-03-11 14:31:04.595 -- [main] INFO o.a.coyote.http11.Http11NioProtocol.log - Initializing ProtocolHandler ["http-nio-2021"]
2021-03-11 14:31:04.596 -- [main] INFO o.a.catalina.core.StandardService.log - Starting service [Tomcat]
2021-03-11 14:31:04.598 -- [main] INFO o.a.catalina.core.StandardEngine.log - Starting Servlet engine: [Apache Tomcat/9.0.27]
2021-03-11 14:31:04.778 -- [main] INFO o.a.c.c.C.[.[.[/xiaotong-ai-web-data].log - Initializing Spring embedded WebApplicationContext
2021-03-11 14:31:04.779 -- [main] INFO o.s.web.context.ContextLoader.prepareWebApplicationContext - Root WebApplicationContext: initialization completed in 2698 ms
2021-03-11 14:31:05.496 -- [main] INFO o.h.validator.internal.util.Version.<clinit> - HV000001: Hibernate Validator 6.0.17.Final
2021-03-11 14:31:06.144 -- [main] INFO o.s.s.c.ThreadPoolTaskExecutor.initialize - Initializing ExecutorService 'applicationTaskExecutor'
2021-03-11 14:31:06.573 -- [main] INFO o.a.coyote.http11.Http11NioProtocol.log - Starting ProtocolHandler ["http-nio-2021"]
2021-03-11 14:31:06.672 -- [main] INFO o.s.b.w.e.tomcat.TomcatWebServer.start - Tomcat started on port(s): 2021 (http) with context path '/xiaotong-ai-web-data'
2021-03-11 14:31:06.685 -- [main] INFO c.x.r.d.XiaotongReceiveDataWebApplication.logStarted - Started XiaotongReceiveDataWebApplication in 5.998 seconds (JVM running for 7.082)
[root@rensun xiaotong_receive_data_web]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3f62c734a446 docker.io/receive-data.io:xiaotong_receive_data_web "java -jar /xiaoto..." 2 minutes ago Exited (130) 34 seconds ago ecstatic_mestorf
7bd9d40daa65 mysql:5.7.11 "docker-entrypoint..." 2 months ago Exited (0) 2 hours ago mysql-lv
8107acbd998b portainer/portainer "/portainer" 4 months ago Up About an hour 0.0.0.0:9000->9000/tcp docker-web
[root@rensun xiaotong_receive_data_web]# docker export 3f62c734a446 > xiaotong_receive_data_web.tar
[root@rensun xiaotong_receive_data_web]# ll
total 152996
-rw-r--r-- 1 root root 230 Mar 11 19:55 Dockerfile
drwxr-xr-x 2 root root 4096 Mar 4 11:22 logs
-rw-r--r-- 1 root root 1790 Mar 9 01:52 pom.xml
drwxr-xr-x 4 root root 4096 Jan 14 15:23 src
drwxr-xr-x 8 root root 4096 Mar 11 20:18 target
-rw-r--r-- 1 root root 14013 Mar 9 01:53 xiaotong_receive_data_web.iml
-rw-r--r-- 1 root root 156630016 Mar 11 22:37 xiaotong_receive_data_web.tar
[root@rensun xiaotong_receive_data_web]#
5.镜像上传部署服务器,导入镜像运行容器
[root@rensun local]# ll
total 153020
drwxr-xr-x 7 root root 4096 Feb 24 04:01 aegis
drwxr-xr-x. 2 root root 4096 Apr 11 2018 bin
drwxr-xr-x. 2 root root 4096 Apr 11 2018 etc
drwxr-xr-x. 2 root root 4096 Apr 11 2018 games
drwxr-xr-x. 2 root root 4096 Apr 11 2018 include
drwxr-xr-x 3 root root 4096 Nov 10 14:00 install_package
drwxr-xr-x 3 root root 4096 Nov 9 15:32 java
drwxr-xr-x. 2 root root 4096 Apr 11 2018 lib
drwxr-xr-x. 2 root root 4096 Apr 11 2018 lib64
drwxr-xr-x. 2 root root 4096 Apr 11 2018 libexec
drwxr-xr-x 12 root root 4096 Nov 10 18:44 nginx
drwxr-xr-x. 2 root root 4096 Apr 11 2018 sbin
drwxr-xr-x. 7 root root 4096 Jan 28 22:43 share
drwxr-xr-x. 2 root root 4096 Apr 11 2018 src
drwxr-xr-x 2 root root 4096 Nov 11 10:09 test
-rw-r--r-- 1 root root 156630016 Mar 11 22:37 xiaotong_receive_data_web.tar
[root@rensun local]# docker import - xiaotong_receive_data_web < xiaotong_receive_data_web.tar
sha256:db13725517354315ed9671ec94e0934b9f1e712bf867d732533caec167cdd874
[root@rensun local]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
xiaotong_receive_data_web latest db1372551735 10 seconds ago 155 MB
docker.io/portainer/portainer latest 62771b0b9b09 7 months ago 79.1 MB
docker.io/openjdk 8-jdk-alpine a3562aa0b991 22 months ago 105 MB
提示 |
---|
本人以抱着学习的态度去分享,以上内容如有雷同,不胜荣幸!如有不足,欢迎评论留言! |
Spring Boot项目打包Docker镜像相关推荐
- spring boot项目生成docker镜像并完成容器部署
一.问题产生 把spring boot项目生成的jar打成docker镜像并生成docker容器完成部署是比较简单方便的部署方式,而且部署过程很少会出错. 二.部署步骤 1.利用maven或者grad ...
- 将Spring Boot项目打包成jar包war包
任务一:将Spring Boot项目打包成jar包 1.在pom.xml文件中添加依赖 2.通过cmd命令行来进行打包jar包(首先进入项目的目录中) 3.进入项目中的target目录下查看包 4.使 ...
- spring项目搭建云服务器,Spring Boot项目打包并部署到云服务器
Spring Boot项目打包并部署到云服务器 一.云服务器的环境 OS: CentOS 7 Jdk 1.8 Spring Boot自动集成Tomcat,不需要单独配置 二.本地Spring Boot ...
- SpringCloud项目打包Docker镜像并发布到Harbor仓库
SpringCloud项目打包Docker镜像并发布到Harbor仓库 1. Docker-compose安装 2. Harbor仓库搭建 3. Docker环境配置 4. 项目配置 1. Docke ...
- Spring Boot项目打包部署
一.Spring Boot项目打成jar包 1. 检查pom.xml中的<packaging></packaging>中的配置内容是否是jar 2. 导入Spring Boot ...
- docker打包镜像上传_Jenkins | 一键打包部署Spring Boot 应用的Docker镜像
一.前言 1.本文主要内容 将在项目中实际使用到的相关东西整理记录一波,同时可以方便其他同学在使用到的时候参考一下(自己也备忘),有不对的地方,欢迎指出~~ Docker部署SpringBoot 项目 ...
- Spring Boot 分层构建 Docker 镜像实战
目录 一.什么是镜像分层 二.SpringBoot 2.3.x 新增对分层的支持 三.创建测试的 SpringBoot 应用 1.Maven 中引入相关依赖和插件 2.创建测试的 Controller ...
- 我司Spring Boot 项目打包 + Shell 脚本部署详细总结,太有用了!
欢迎关注方志朋的博客,回复"666"获面试宝典 本篇和大家分享的是 Spring Boot 打包并结合 Shell 脚本命令部署,重点在分享一个shell 程序启动工具,希望能便利 ...
- 后端技术:Spring Boot 项目打包 + Shell 脚本部署实践,太有用了!
本篇和大家分享的是 Spring Boot 打包并结合 Shell 脚本命令部署,重点在分享一个shell 程序启动工具,希望能便利工作: profiles指定不同环境的配置 maven-assemb ...
最新文章
- 通俗讲解自底向上构建知识图谱全过程
- c语言搜索多层文件夹,c语言 遍历搜索文件夹(获取文件夹中所有内容)
- 如何在 Mac 上的“快速查看”中查看和编辑文件
- WordPress可视化拖拽自助建站主题The7 V10.0.0
- TensorFlow第八步 Nesterov's accelerated gradient descent+L2 regularization
- radiobutton 设置单选项目标
- linux init 参数,Objective-C中实现覆写init函数以及在初始化时添加参数
- 几行Python代码打造自己的磁盘垃圾文件清理器
- 一个 ARK工具: XueTr类似ICEWORLD
- 16.最接近的三数之和
- 极化码 极化现象matlab仿真(信道容量,巴氏参数,高斯近似三种方法)
- Android即时通讯实现原理
- CMMB手机电视入网咋就这么难?
- tampermonkey油猴实现自动定时刷新页面,刷访问量
- Vue 动态响应数据变化
- 网页|利用touch实现下拉刷新
- 兜兜转转,Image图片转换成PDF还是这款工具靠谱
- 2020牛客暑期多校训练营(第九场)	The Escape Plan of Groundhog
- intelliJ IDE 打包出错:F:/InterlliJ IDEA/Demo/src/main/java/META-INF/MANIFEST.MF' already exists in VFS
- 从C/C++到Python(之二)(By Robinvane Suen)
热门文章
- iOS开发:Core Animation编程指南
- 学习Zynq笔记(3):基于zynq的雷达信号处理系统学习笔记
- 安卓的短信记录导入苹果_分享一下苹果手机怎么将短信备份导入到安卓手机的方法...
- python在线编程平台-python在线编程
- 看不懂别做爬虫-----python scrapy爬取淘宝
- mysql show where_MySQL SHOW命令使用详解
- 爬取建标库规范全文到本地word(selenium+python-docx+tesseract实现)
- HashMap和HashTable的区别?但是如果想线程安全有想效率高?
- 视频加入马赛克_会声会影篇
- Cdiscount的订单管理ERP怎么选择?无忧易售ERP已与Cdiscount达成合作,完成对接