springBoot微服务打包成docker镜像

本文涉及的产品
服务治理 MSE Sentinel/OpenSergo,Agent数量 不受限
简介: 使用docker跑服务非常方便,不需要在服务实例上繁琐的安装运行环境,通过编写dockefile快速构建镜像,能够快速运行应用,开发首选

springBoot微服务打包成docker镜像

使用docker跑服务非常方便,不需要在服务实例上繁琐的安装运行环境,通过编写dockefile快速构建镜像,能够快速运行应用,开发首选

1、准备jar包

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-flBRkpY9-1624332371447)(C:\Users\Meet\AppData\Roaming\Typora\typora-user-images\image-20210622102829673.png)]

2、编写DockerFile

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-bWuubFFB-1624332371451)(C:\Users\Meet\AppData\Roaming\Typora\typora-user-images\image-20210622102919722.png)]

3、上传,build生成镜像

[root@VM-8-9-centos test]# ls
Dockerfile  test-0.0.1-SNAPSHOT.jar
[root@VM-8-9-centos test]# docker build -f Dockerfile  -t springboot-image
"docker build" requires exactly 1 argument.
See 'docker build --help'.

Usage:  docker build [OPTIONS] PATH | URL | -

Build an image from a Dockerfile
[root@VM-8-9-centos test]# docker build -f Dockerfile  -t springboot-image .
Sending build context to Docker daemon   17.6MB
Step 1/5 : FROM java:8
8: Pulling from library/java
5040bd298390: Pull complete 
fce5728aad85: Pull complete 
76610ec20bf5: Pull complete 
60170fec2151: Pull complete 
e98f73de8f0d: Pull complete 
11f7af24ed9c: Pull complete 
49e2d6393f32: Pull complete 
bb9cdec9c7f3: Pull complete 
Digest: sha256:c1ff613e8ba25833d2e1940da0940c3824f03f802c449f3d1815a66b7f8c0e9d
Status: Downloaded newer image for java:8
 ---> d23bdf5b1b1b
Step 2/5 : COPY *.jar /app.jar
 ---> 3a53cad9ae39
Step 3/5 : CMD ["--server.port=8080"]
 ---> Running in b53ca055dafd
Removing intermediate container b53ca055dafd
 ---> 3aa1b8767fea
Step 4/5 : EXPOSE 8080
 ---> Running in 20c50a75f15c
Removing intermediate container 20c50a75f15c
 ---> b8e7072c5ae8
Step 5/5 : ENTRYPOINT ["java","-jar","/app.jar"]
 ---> Running in 5edbe3e7a251
Removing intermediate container 5edbe3e7a251
 ---> d99e96e3c5dd
Successfully built d99e96e3c5dd
Successfully tagged springboot-image:latest

4、运行容器,访问

[root@VM-8-9-centos test]# docker images
REPOSITORY         TAG                               IMAGE ID       CREATED              SIZE
springboot-image   latest                            d99e96e3c5dd   About a minute ago   661MB
tomcat-image       1.0                               271418e6337f   36 hours ago         638MB
tomcat             9.0.48-jdk8-adoptopenjdk-openj9   d716ed54947b   5 days ago           386MB
redis              latest                            fad0ee7e917a   2 weeks ago          105MB
nginx              latest                            d1a364dc548d   3 weeks ago          133MB
mysql              8.0.25                            c0cdc95609f1   5 weeks ago          556MB
centos             latest                            300e315adb2f   6 months ago         209MB
java               8                                 d23bdf5b1b1b   4 years ago          643MB
[root@VM-8-9-centos test]# docker run -d -p 9999:8080 --name springboot-test springboot-image

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-xIOTFeKg-1624332371453)(C:\Users\Meet\AppData\Roaming\Typora\typora-user-images\image-20210622103520607.png)]

相关文章
|
7天前
|
Java API 微服务
【Spring Boot系列】通过OpenAPI规范构建微服务服务接口
【4月更文挑战第5天】通过OpenAPI接口构建Spring Boot服务RestAPI接口
|
4天前
|
存储 Java 时序数据库
【SpringBoot系列】微服务监测(常用指标及自定义指标)
【4月更文挑战第6天】SpringBoot微服务的监测指标及自定义指标讲解
|
1天前
|
机器学习/深度学习 负载均衡 Java
【SpringBoot系列】微服务远程调用Open Feign深度学习
【4月更文挑战第9天】微服务远程调度open Feign 框架学习
|
2天前
|
存储 Ubuntu Linux
[Docker] 镜像讲解
[Docker] 镜像讲解
|
3天前
|
Java 关系型数据库 数据库
【SpringBoot系列】微服务集成Flyway
【4月更文挑战第7天】SpringBoot微服务集成Flyway
【SpringBoot系列】微服务集成Flyway
|
5天前
|
运维 前端开发 Devops
云效产品使用报错问题之流水线打包docker镜像时报网络代理有问题如何解决
本合集将整理呈现用户在使用过程中遇到的报错及其对应的解决办法,包括但不限于账户权限设置错误、项目配置不正确、代码提交冲突、构建任务执行失败、测试环境异常、需求流转阻塞等问题。阿里云云效是一站式企业级研发协同和DevOps平台,为企业提供从需求规划、开发、测试、发布到运维、运营的全流程端到端服务和工具支撑,致力于提升企业的研发效能和创新能力。
|
16天前
|
应用服务中间件 Docker 容器
docker 镜像常用命令
docker 镜像常用命令
38 0
|
16天前
|
Linux Shell 虚拟化
linux 部署docker容器虚拟化平台(二)--------docker 镜像制作方法
linux 部署docker容器虚拟化平台(二)--------docker 镜像制作方法
28 0
|
24天前
|
存储 Kubernetes API
Docker拉取镜像或者kubectl出现的这个解决方案x509: certificate signed by unknown authority
Docker拉取镜像或者kubectl出现的这个解决方案x509: certificate signed by unknown authority
61 2
|
25天前
|
Linux Docker 容器
Linux彻底卸载Docker包括运行拉取的镜像
Linux彻底卸载Docker包括运行拉取的镜像
24 1