1、构架springboot项目
2、打包应用
3、编写dockerfile
FROM java:8
COPY *.jar /app.jar
CMD ["--server.port=8080"]
EXPOSE 8080
ENTRYPOINT ["java","-jar","/app.jar"]
4、构建镜像
[root@iZwz9gcg5lpw0sp5r86b4dZ idea]# ls
Dockerfile springbootdemo-0.0.1-SNAPSHOT.jar
[root@iZwz9gcg5lpw0sp5r86b4dZ idea]# docker build -t young666 .
Sending build context to Docker daemon 47.06MB
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
---> 529e37879e3c
Step 3/5 : CMD ["--server.port=8080"]
---> Running in 8c2e482da3ba
Removing intermediate container 8c2e482da3ba
---> f45efff2bedc
Step 4/5 : EXPOSE 8080
---> Running in 985c426ce7ec
Removing intermediate container 985c426ce7ec
---> d167cd7a15ec
Step 5/5 : ENTRYPOINT ["java","-jar","/app.jar"]
---> Running in 657959521ec7
Removing intermediate container 657959521ec7
---> 116a5a54ddbd
Successfully built 116a5a54ddbd
Successfully tagged young666:latest
[root@iZwz9gcg5lpw0sp5r86b4dZ idea]# ll
total 45960
-rw-r--r-- 1 root root 120 Jun 17 16:28 Dockerfile
-rw-r--r-- 1 root root 47056728 Jun 17 16:29 springbootdemo-0.0.1-SNAPSHOT.jar
5、发布运行