溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

Springboot微服務(wù)打包Docker鏡像流程解析

發(fā)布時(shí)間:2020-09-18 03:09:52 來源:腳本之家 閱讀:214 作者:古城,老巷 欄目:開發(fā)技術(shù)

1.構(gòu)建springboot項(xiàng)目

2.打包應(yīng)用

3.編寫dockerfile

4.構(gòu)建鏡像

5.發(fā)布運(yùn)行!

[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"]

# 構(gòu)建鏡像
[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

## 運(yùn)行鏡像
[root@localhost demo]# docker run -d -p 8080:8080 myapp 
4aa0eefb1c5d53d752ade949625683a61acc2e5bfe642614b1ae68533b279dae

# 訪問測(cè)試
[root@localhost demo]# curl localhost:8080/hello/hello
hello[root@localhost demo]# 

# 訪問成功

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持億速云。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI