docker部署springboot应用
生活随笔
收集整理的這篇文章主要介紹了
docker部署springboot应用
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
2019獨角獸企業重金招聘Python工程師標準>>>
1、將springboot應用打包成可執行jar
個人打包的項目地址:https://gitee.com/suzhe/springboot-item
進入item-hello目錄執行如下命令打包。
mvn package -Dmaven.test.skip=true -Ptest?
2、可執行jar包上傳到linux執行目錄
這里上傳到了Linux中的目錄 /app/hello-app
[root@VM_108_39_centos hello-app]# pwd /apps/hello-app [root@VM_108_39_centos hello-app]# ll -rw-r--r-- 1 root root 17756779 Dec 13 09:32 item-hello-1.0-SNAPSHOT.jar [root@VM_108_39_centos hello-app]# ?3、在該目錄下創建Dockerfile文件
From java:8 # 將本地文件夾掛載到當前容器 VOLUME /apps/tmp # 復制文件到容器 ADD item-hello-1.0-SNAPSHOT.jar /app.jar # 聲明需要暴露的端口 EXPOSE 8090 # 配置容器啟動后執行的命令 ENTRYPOINT ["java","-jar","/app.jar"] ??
[root@VM_108_39_centos hello-app]# ll total 17348 -rw-r--r-- 1 root root ? ? ?256 Dec 13 09:14 Dockerfile -rw-r--r-- 1 root root 17756779 Dec 13 09:32 item-hello-1.0-SNAPSHOT.jar [root@VM_108_39_centos hello-app]# ??
4、使用docker build命令構建鏡像
[root@VM_108_39_centos hello-app]# docker build -t helloapp:0.0.1 . Sending build context to Docker daemon 17.76 MB Step 1/5 : FROM java:8 Trying to pull repository docker.io/library/java ... sha256:c1ff613e8ba25833d2e1940da0940c3824f03f802c449f3d1815a66b7f8c0e9d: Pulling from docker.io/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 docker.io/java:8---> d23bdf5b1b1b Step 2/5 : VOLUME /apps/tmp---> Running in 3bb3065ab081---> b2ae8abc4db6 Removing intermediate container 3bb3065ab081 Step 3/5 : ADD item-hello-1.0-SNAPSHOT.jar /app.jar---> b260ef58051a Removing intermediate container 1b9bfb5dbdf7 Step 4/5 : EXPOSE 8090---> Running in 9b77153d75ea---> aa1ea26fa596 Removing intermediate container 9b77153d75ea Step 5/5 : ENTRYPOINT java -jar /app.jar---> Running in 5a02f129583a---> 65724311b315 Removing intermediate container 5a02f129583a Successfully built 65724311b315 #構建成功 [root@VM_108_39_centos hello-app]#格式: docker build -t 鏡像名稱:標簽 Dockerfile的相對位置 這里的.代表當前目錄
在這里,使用-t選項指定了鏡像的標簽。
5、啟動鏡像,加-d可在后臺啟動
[root@VM_108_39_centos hello-app]# docker run -d -p 8090:8090 helloapp:0.0.1 d296c55ebe53061819e88306db8309266dd97491494e5b431adf961db39d5c58 [root@VM_108_39_centos hello-app]# docker ps CONTAINER ID ? ? ? IMAGE ? ? ? ? ? ? ? COMMAND ? ? ? ? ? ? ? ? CREATED ? ? ? ? ? ? STATUS ? ? ? ? ? ? PORTS ? ? ? ? ? ? ? ? ? NAMES d296c55ebe53 ? ? ? helloapp:0.0.1 ? ? ?"java -jar /app.jar" ? ? 10 seconds ago ? ? Up 8 [root@VM_108_39_centos hello-app]# ?6、測試應用
訪問對應的服務鏈接。
轉載于:https://my.oschina.net/suzheworld/blog/2990878
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的docker部署springboot应用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 入门级Wi-Fi 6路由器的好选择,京东
- 下一篇: 如果近期打算买路由器-如果近期打算买路由