码迷,mamicode.com
首页 > 编程语言 > 详细

springboot微服务打包Docker镜像

时间:2020-08-19 19:10:33      阅读:79      评论:0      收藏:0      [点我收藏+]

标签:lan   repos   dia   nload   container   java   library   copy   inter   

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

# 访问成功

springboot微服务打包Docker镜像

标签:lan   repos   dia   nload   container   java   library   copy   inter   

原文地址:https://www.cnblogs.com/yinxd/p/13513845.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!