700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > Spring Boot项目打包Docker镜像

Spring Boot项目打包Docker镜像

时间:2018-09-10 08:28:05

相关推荐

Spring Boot项目打包Docker镜像

Spring Boot项目打包Docker镜像

1.编写 Dockerfile 文件2.加入 spring boot 根路径, 进行 mvn package 打包3.打包上传项目并解压4.进入 xiaotong_receive_data_web 项目目录执行打包命令、查看镜像、运行容器、查看容器、根据容器ID导出镜像文件 xiaotong_receive_data_web.tar5.镜像上传部署服务器,导入镜像运行容器

1.编写 Dockerfile 文件

FROM openjdk:8-jdk-alpineARG JAR_FILE=target/xiaotong_receive_data_service-0.0.1-SNAPSHOT.jarCOPY ${JAR_FILE} xiaotong_receive_data_service-0.0.1-SNAPSHOT.jarENTRYPOINT ["java","-jar","/xiaotong_receive_data_service-0.0.1-SNAPSHOT.jar"]

2.加入 spring boot 根路径, 进行 mvn package 打包

3.打包上传项目并解压

drwxr-xr-x 4 root root4096 Mar 11 21:14 xiaotong_receive_data_service-rw-r--r-- 1 root root 64181817 Mar 11 20:21 xiaotong_receive_data_service.zipdrwxr-xr-x 5 root root4096 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]# lltotal 36-rw-r--r-- 1 root root 230 Mar 11 19:55 Dockerfiledrwxr-xr-x 2 root root 4096 Mar 4 11:22 logs-rw-r--r-- 1 root root 1790 Mar 9 01:52 pom.xmldrwxr-xr-x 4 root root 4096 Jan 14 15:23 srcdrwxr-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 MBStep 1/4 : FROM openjdk:8-jdk-alpine---> a3562aa0b991Step 2/4 : ARG JAR_FILE=target/xiaotong_receive_data_web-0.0.1-SNAPSHOT.jar---> Using cache---> 76283f52d6e7Step 3/4 : COPY ${JAR_FILE} xiaotong_receive_data_web-0.0.1-SNAPSHOT.jar---> Using cache---> 4364a9bae961Step 4/4 : ENTRYPOINT java -jar /xiaotong_receive_data_web-0.0.1-SNAPSHOT.jar---> Using cache---> deb721008ea6Successfully built deb721008ea6[root@rensun xiaotong_receive_data_web]# docker image ls REPOSITORY TAG IMAGE ID CREATED SIZEdocker.io/receive-data.io xiaotong_receive_data_service 26b876d48521 About an hour ago 176 MBdocker.io/receive-data.io xiaotong_receive_data_web deb721008ea6 About an hour ago 155 MBdocker.io/portainer/portainer latest62771b0b9b09 7 months ago 79.1 MBdocker.io/openjdk8-jdk-alpinea3562aa0b991 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)-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 /)-03-11 14:31:01.964 -- [main] INFO c.x.r.d.XiaotongReceiveDataWebApplication.logStartupProfileInfo - No active profile set, falling back to default profiles: default-03-11 14:31:04.561 -- [main] INFO o.s.b.w.e.tomcat.TomcatWebServer.initialize - Tomcat initialized with port(s): (http)-03-11 14:31:04.595 -- [main] INFO o.a.coyote.http11.Http11NioProtocol.log - Initializing ProtocolHandler ["http-nio-"]-03-11 14:31:04.596 -- [main] INFO o.a.catalina.core.StandardService.log - Starting service [Tomcat]-03-11 14:31:04.598 -- [main] INFO o.a.catalina.core.StandardEngine.log - Starting Servlet engine: [Apache Tomcat/9.0.27]-03-11 14:31:04.778 -- [main] INFO o.a.c.c.C.[.[.[/xiaotong-ai-web-data].log - Initializing Spring embedded WebApplicationContext-03-11 14:31:04.779 -- [main] INFO o.s.web.context.ContextLoader.prepareWebApplicationContext - Root WebApplicationContext: initialization completed in 2698 ms-03-11 14:31:05.496 -- [main] INFO o.h.validator.internal.util.Version.<clinit> - HV000001: Hibernate Validator 6.0.17.Final-03-11 14:31:06.144 -- [main] INFO o.s.s.c.ThreadPoolTaskExecutor.initialize - Initializing ExecutorService 'applicationTaskExecutor'-03-11 14:31:06.573 -- [main] INFO o.a.coyote.http11.Http11NioProtocol.log - Starting ProtocolHandler ["http-nio-"]-03-11 14:31:06.672 -- [main] INFO o.s.b.w.e.tomcat.TomcatWebServer.start - Tomcat started on port(s): (http) with context path '/xiaotong-ai-web-data'-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 -aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTSNAMES3f62c734a446 docker.io/receive-data.io:xiaotong_receive_data_web "java -jar /xiaoto..." 2 minutes ago Exited (130) 34 seconds ago ecstatic_mestorf7bd9d40daa65 mysql:5.7.11"docker-entrypoint..." 2 months ago Exited (0) 2 hours agomysql-lv8107acbd998b 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]# lltotal 152996-rw-r--r-- 1 root root 230 Mar 11 19:55 Dockerfiledrwxr-xr-x 2 root root4096 Mar 4 11:22 logs-rw-r--r-- 1 root root1790 Mar 9 01:52 pom.xmldrwxr-xr-x 4 root root4096 Jan 14 15:23 srcdrwxr-xr-x 8 root root4096 Mar 11 20:18 target-rw-r--r-- 1 root root14013 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]# lltotal 153020drwxr-xr-x 7 root root4096 Feb 24 04:01 aegisdrwxr-xr-x. 2 root root4096 Apr 11 bindrwxr-xr-x. 2 root root4096 Apr 11 etcdrwxr-xr-x. 2 root root4096 Apr 11 gamesdrwxr-xr-x. 2 root root4096 Apr 11 includedrwxr-xr-x 3 root root4096 Nov 10 14:00 install_packagedrwxr-xr-x 3 root root4096 Nov 9 15:32 javadrwxr-xr-x. 2 root root4096 Apr 11 libdrwxr-xr-x. 2 root root4096 Apr 11 lib64drwxr-xr-x. 2 root root4096 Apr 11 libexecdrwxr-xr-x 12 root root4096 Nov 10 18:44 nginxdrwxr-xr-x. 2 root root4096 Apr 11 sbindrwxr-xr-x. 7 root root4096 Jan 28 22:43 sharedrwxr-xr-x. 2 root root4096 Apr 11 srcdrwxr-xr-x 2 root root4096 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 imagesREPOSITORY TAG IMAGE ID CREATED SIZExiaotong_receive_data_web latest db1372551735 10 seconds ago155 MBdocker.io/portainer/portainer latest 62771b0b9b09 7 months ago 79.1 MBdocker.io/openjdk8-jdk-alpine a3562aa0b991 22 months ago 105 MB

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。