Dockerfile部署springboot

准备springboot项目


使用maven install打包,idea会将其发布到maven仓库,直接用就好。或者会在target目录中。

本地测试确保springboot的jar包没问题


Dockerfile方式部署springboot


如果我们不使用docker容器的,那么我们正常发布就是java -jar跑起来。
现在只是我们编写脚本生成镜像运行,而编写脚本的内容,还是怎么运行java -jar。

FROM java:8
MAINTAINER sunpy
COPY ./teacher-service-0.0.1-SNAPSHOT.jar /teacher-service.jar
ENTRYPOINT ["java","-jar","teacher-service.jar"]

上面要确保,当前目录里面存在teacher-service-0.0.1-SNAPSHOT.jar文件。

生成镜像:

[root@ecs-140051 app]# docker build -t teacher-service:v2 .
Sending build context to Docker daemon  59.27MB
Step 1/4 : FROM java:8
 ---> d23bdf5b1b1b
Step 2/4 : MAINTAINER sunpy
 ---> Using cache
 ---> db34617ece11
Step 3/4 : COPY ./teacher-service-0.0.1-SNAPSHOT.jar /teacher-service.jar
 ---> c9687ec459b3
Step 4/4 : ENTRYPOINT ["java","-jar","teacher-service.jar"]
 ---> Running in 919b43caf9e9
Removing intermediate container 919b43caf9e9
 ---> f7d17d63bf08
Successfully built f7d17d63bf08
Successfully tagged teacher-service:v2


运行镜像生成容器:

[root@ecs-140051 app]# docker run -d --name teacher-service-2 -p 3801:8080 teacher-service:v2
692b8d4e49d9d4b7a5046d80259f3f1bbf9a7f6923b52ab01cf27655da02e084

[root@ecs-140051 app]# docker ps -a
CONTAINER ID   IMAGE                COMMAND                  CREATED          STATUS                     PORTS                                                  NAMES
692b8d4e49d9   teacher-service:v2   "java -jar teacher-s…"   11 seconds ago   Up 11 seconds              0.0.0.0:3801->8080/tcp, :::3801->8080/tcp              teacher-service-2

外部访问:

你可能感兴趣的:(Dockerfile部署springboot)