Springboot微服务打包Docker镜像流程解析
作者:古城,老巷 时间:2022-02-23 19:39:00
1.构建springboot项目
2.打包应用
3.编写dockerfile
4.构建镜像
5.发布运行!
[root@localhost demo]# ls
demo02-0.0.1-SNAPSHOT.jar Dockerfile
# Dockerfile文件
[root@localhost demo]# cat Dockerfile
FROM java:8
COPY *.jar /app.jar
CMD ["--server.port=8080"]
EXPOSE 8080
ENTRYPOINT ["java","-jar","/app.jar"]
# 构建镜像
[root@localhost demo]# docker build -t myapp .
Sending build context to Docker daemon 16.52MB
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
---> 5da95c636893
Step 3/5 : CMD ["--server.port=8080"]
---> Running in fa572a071b60
Removing intermediate container fa572a071b60
---> 923a3dc22971
Step 4/5 : EXPOSE 8080
---> Running in ab336abf9423
Removing intermediate container ab336abf9423
---> 41946a7a1a04
Step 5/5 : ENTRYPOINT ["java","-jar","/app.jar"]
---> Running in dcd4cb40838c
Removing intermediate container dcd4cb40838c
---> edcc53f97c94
Successfully built edcc53f97c94
Successfully tagged myapp:latest
[root@localhost demo]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
myapp latest edcc53f97c94 About a minute ago 660MB
java 8 d23bdf5b1b1b 3 years ago 643MB
## 运行镜像
[root@localhost demo]# docker run -d -p 8080:8080 myapp
4aa0eefb1c5d53d752ade949625683a61acc2e5bfe642614b1ae68533b279dae
# 访问测试
[root@localhost demo]# curl localhost:8080/hello/hello
hello[root@localhost demo]#
# 访问成功
来源:https://www.cnblogs.com/yinxd/p/13513845.html
标签:Spring,boot,微服务,打包,Docker,镜像
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
java使用异或实现变量互换和异或加密解密示例
2023-10-19 16:53:38
java 遍历request中的所有表单数据的实例代码
2021-10-21 11:19:26
详解Java编程中protected修饰符与static修饰符的作用
2022-05-11 03:53:17
![](https://img.aspxhome.com/file/2023/9/62959_0s.png)
深入解析Spring Cloud内置的Zuul过滤器
2022-05-16 12:49:04
详解如何实现SpringBoot的底层注解
2023-11-23 06:21:04
![](https://img.aspxhome.com/file/2023/0/59040_0s.png)
Spring如何消除代码中的if-else/switch-case
2021-12-12 03:04:47
分析Java设计模式之组合模式
2023-11-25 13:13:30
![](https://img.aspxhome.com/file/2023/6/59856_0s.jpg)
Flutter 日历组件简单实现
2023-10-21 11:04:35
Java实现FTP上传与下载功能
2021-09-22 18:28:51
![](https://img.aspxhome.com/file/2023/0/62340_0s.jpg)
jdk动态代理源码分析过程
2023-03-01 05:05:59
![](https://img.aspxhome.com/file/2023/7/68157_0s.png)
Java多线程与线程池技术分享
2021-07-25 07:35:11
![](https://img.aspxhome.com/file/2023/2/80322_0s.jpg)
Java调用Oracle存储过程详解
2022-09-09 03:19:45
c#网络唤醒功能实现
2022-07-03 03:26:51
![](https://img.aspxhome.com/file/2023/3/84443_0s.jpg)
Java分形绘制山脉模型
2023-05-10 00:51:29
![](https://img.aspxhome.com/file/2023/1/80901_0s.jpg)
在Android设备上搭建Web服务器的方法
2023-06-23 23:38:36
![](https://img.aspxhome.com/file/2023/9/82419_0s.gif)
C#软件注册码的实现代码
2021-10-14 06:14:38
java查找字符串中的包含子字符串的个数实现代码
2022-08-15 17:48:45
Spring Security之默认的过滤器链及自定义Filter操作
2023-11-24 02:48:35
![](https://img.aspxhome.com/file/2023/3/59733_0s.png)
Java线程通信之wait-notify通信方式详解
2022-05-17 19:35:46
![](https://img.aspxhome.com/file/2023/4/75434_0s.png)
Java守护线程实例详解_动力节点Java学院整理
2023-03-29 08:14:30
![](https://img.aspxhome.com/file/2023/5/60175_0s.png)