目的:
将项目打包成docker镜像发布到服务器
将SpringBoot项目进行打包
创建Dockerfile文件
jar包本地运行没问题之后,将jar包和Dockerfile文件上传至linux服务器
我这里先启动了openjdk的镜像
将项目打成docker镜像,命令后面有个 .
docker build -t yutao666 .
[root@localhost test]# docker build -t yutao666 . Sending build context to Docker daemon 69.4MB Step 1/5 : FROM openjdk ---> 5e28ba2b4cdb Step 2/5 : COPY *.jar /app.jar ---> 4a87bb06da90 Step 3/5 : CMD ["--server.prot=8080"] ---> Running in 88a0e5e23b5d Removing intermediate container 88a0e5e23b5d ---> 6a1b6abead85 Step 4/5 : EXPOSE 8080 ---> Running in d1f514b5e6ae Removing intermediate container d1f514b5e6ae ---> 0539168cd6cc Step 5/5 : ENTRYPOINT ["java","-jar","/app.jar"] ---> Running in c3b46aba88d0 Removing intermediate container c3b46aba88d0 ---> ac6735e9a7a2 Successfully built ac6735e9a7a2 Successfully tagged yutao666:latest
查看镜像
[root@localhost test]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE yutao666 latest ac6735e9a7a2 7 seconds ago 541MB tomcat latest 5eb506608219 4 hours ago 685MB redis latest 1ca2c2a1b554 6 days ago 117MB openjdk 8 c43167b660ad 7 days ago 526MB mysql 5.7 8aa4b5ffb001 2 weeks ago 462MB openjdk latest 5e28ba2b4cdb 2 weeks ago 471MB nginx latest fa5269854a5e 3 weeks ago 142MB centos latest 5d0da3dc9764 8 months ago 231MB
直接运行镜像
[root@localhost test]# docker run -d -it -p 8080:8080 yutao888 ad4d6e63611c456c33444362767ae54a1d3f2831652e2ade6dc285f142feb230
查看镜像是否启动成功
[root@localhost test]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES ad4d6e63611c yutao666 "java -jar /app.jar …" 3 seconds ago Up 2 seconds 8080/tcp great_booth e8a75344ac62 openjdk "/bin/bash" 24 minutes ago Up 24 minutes exciting_euler
访问成功!
PS:我这里写的是一个小demo,主要是打包流程,真正打包项目的时候将项目镜像交给运维或者测试,或者直接上传至dockerhub,别人直接拉下来,docker run 就ok了!
原文链接:https://blog.csdn.net/m0_58709145/article/details/124842067?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522171836832416800225563159%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fblog.%2522%257D&request_id=171836832416800225563159&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~blog~first_rank_ecpm_v1~times_rank-30-124842067-null-null.nonecase&utm_term=docker%E9%95%9C%E5%83%8F
© 版权声明
声明📢本站内容均来自互联网,归原创作者所有,如有侵权必删除。
本站文章皆由CC-4.0协议发布,如无来源则为原创,转载请注明出处。
THE END