首頁 > 軟體

springboot執行到dokcer中 dockerfile的場景分析

2022-03-03 13:01:22

1.場景

stringboot - > spring boot .jar -> dockerfile---> run dokcerfile

2.編寫springboot 專案打包上傳linux伺服器

2.1 將jar 包和 docker放到同一個目錄

-rw-r--r-- 1 root root 19514674 2月  27 22:48 myspringbootdocker.jar
[root@basenode springbootdocker]# pwd
/opt/springbootdocker
[root@basenode springbootdocker]# 

2.2 編寫dockerfile

1.需要注意的是 jar包名字不能有大寫
2.Dockerfile 的檔名 首字母D 必須大寫

[root@basenode springbootdocker]# vi Dockerfile 

# 基礎映象使用java
FROM java:8
# 作者
MAINTAINER wudl
# VOLUME 指定臨時檔案目錄為/tmp,在主機/var/lib/docker目錄下建立了一個臨時檔案並連結到容器的/tmp
VOLUME /tmp
# 將jar包新增到容器中並更名為zzyy_docker.jar
ADD myspringbootdocker.jar /myspringbootdocker.jar
# 執行jar包
RUN bash -c 'touch /myspringbootdocker.jar'
ENTRYPOINT ["java","-jar","/myspringbootdocker.jar"]
#暴露18088埠作為微服務
EXPOSE 18088

3. 執行dockerfile

命令 docker build -t myspringbootdocker:1.6 .

[root@basenode springbootdocker]# docker build -t myspringbootdocker:1.6 .
Sending build context to Docker daemon  19.52MB
Step 1/7 : 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/7 : MAINTAINER wudl
 ---> Running in 91addd3bc917
Removing intermediate container 91addd3bc917
 ---> 7982d20f4554
Step 3/7 : VOLUME /tmp
 ---> Running in 6973feea6ef5
Removing intermediate container 6973feea6ef5
 ---> c2feccd04de7
Step 4/7 : ADD myspringbootdocker.jar /myspringbootdocker.jar
 ---> fa79952fe484
Step 5/7 : RUN bash -c 'touch /myspringbootdocker.jar'
 ---> Running in f75bf573ec70
Removing intermediate container f75bf573ec70
 ---> 6d82fe109ae7
Step 6/7 : ENTRYPOINT ["java","-jar","/myspringbootdocker.jar"]
 ---> Running in 3fce2f523b70
Removing intermediate container 3fce2f523b70
 ---> 80ef7731c159
Step 7/7 : EXPOSE 18088
 ---> Running in 2d1179d0cfb4
Removing intermediate container 2d1179d0cfb4
 ---> 3f4e689e54db
Successfully built 3f4e689e54db
Successfully tagged myspringbootdocker:1.6
[root@basenode springbootdocker]# 

4.檢視映象

[root@basenode springbootdocker]# docker images
REPOSITORY                                    TAG                    IMAGE ID       CREATED         SIZE
myspringbootdocker                            1.6                    3f4e689e54db   2 minutes ago   682MB
centosjava8                                   1.5                    14fad190b338   4 weeks ago     801MB
nacos/nacos-server                            v2.0.4                 ea54f31c46e4   5 weeks ago     1.07GB
tomcat                                        latest                 fb5657adc892   2 months ago    680MB
mysql                                         5.7                    c20987f18b13   2 months ago    448MB
apache/incubator-doris                        build-env-latest       cc924653f13d   2 months ago    4.24GB
apache/incubator-doris                        build-env-for-0.15.0   e568f7b2e1d8   3 months ago    3.54GB

5. 執行映象

docker run -d -p 18089:18088 3f4e689e54db
[root@basenode springbootdocker]# docker run -d -p 18089:18088  3f4e689e54db
5040141bd7d5700d8310a70309f940bb452656c0e909c6c6e138f7f6a9f65295
[root@basenode springbootdocker]# 

6. 執行

到此這篇關於springboot執行到dokcer中 dockerfile的文章就介紹到這了,更多相關springboot執行dockerfile內容請搜尋it145.com以前的文章或繼續瀏覽下面的相關文章希望大家以後多多支援it145.com!


IT145.com E-mail:sddin#qq.com