springBoot微服务打包成docker镜像

springBoot微服务打包成docker镜像

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)]

个人博客:https://www.xiaoxuya.top/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

白鸽呀

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值