您好,登錄后才能下訂單哦!
原創(chuàng)文章,歡迎轉(zhuǎn)載。轉(zhuǎn)載請(qǐng)注明:轉(zhuǎn)載自IT人故事會(huì),謝謝!
原文鏈接地址:『高級(jí)篇』docker之DockerSwarm調(diào)整微服務(wù)及服務(wù)配置(29)上次已經(jīng)搭建好了swarm的集群環(huán)境,server01,server02,server03三臺(tái)虛擬機(jī),每一臺(tái)的manager節(jié)點(diǎn)也是work節(jié)點(diǎn),首先我們考慮的問(wèn)題是服務(wù)的發(fā)現(xiàn),從微服務(wù)的角度考慮,我們有得服務(wù)是為了其他服務(wù)使用的,如message service,user service,對(duì)于swarm上,有的需要暴露端口給其他服務(wù)使用,有的是直接通過(guò)服務(wù)的名稱(chēng)就可以訪問(wèn)的,改造模式,改造代碼,然后上傳到鏡像倉(cāng)庫(kù)。最后配置一個(gè)docker stack 把他們的關(guān)系編寫(xiě)出來(lái),一條命令搞定了。源碼:https://github.com/limingios/msA-docker swarm分支
sh
#!/usr/bin/env bash
source ~/.bash_profile
mvn package
docker build -f ./Dockerfile-hub -t zhugeaming/course-dubbo-service:latest .
docker push zhugeaming/course-dubbo-service:latest
>Dockerfile
``` bash
FROM java:openjdk-8
MAINTAINER liming www.idig8.com
COPY target/course-dubbo-service-1.0-SNAPSHOT.jar /course-dubbo-service.jar
ENTRYPOINT ["java","-jar","/course-dubbo-service.jar"]
sh
#!/usr/bin/env bash
source ~/.bash_profile
mvn package
docker build -f ./Dockerfile-hub -t zhugeaming/course-edge-service:latest .
docker push zhugeaming/course-edge-service:latest
>Dockerfile
``` bash
FROM java:openjdk-8
MAINTAINER liming www.idig8.com
COPY target/course-edge-service-1.0-SNAPSHOT.jar /course-edge-service.jar
ENTRYPOINT ["java","-jar","/course-edge-service.jar"]
sh
#!/usr/bin/env bash
source ~/.bash_profile
mvn package
docker build -f ./Dockerfile-hub -t zhugeaming/gataway-zuul:latest .
docker push zhugeaming/gataway-zuul:latest
>Dockfile
``` bash
FROM java:openjdk-8
MAINTAINER liming www.idig8.com
COPY target/gataway-zuul-1.0-SNAPSHOT.jar /gataway-zuul.jar
ENTRYPOINT ["java","-jar","/gataway-zuul.jar"]
sh
#!/usr/bin/env bash source ~/.bash_profile mvn package docker build -f ./Dockerfile-hub -t zhugeaming/user-edge-service:latest . docker push zhugeaming/user-edge-service:latest
Dockerfile
#!/usr/bin/env bash source ~/.bash_profile mvn package docker build -f ./Dockerfile-hub -t zhugeaming/user-edge-service:latest . docker push zhugeaming/user-edge-service:latest
sh
#!/usr/bin/env bash source ~/.bash_profile mvn package docker build -f ./Dockerfile-hub -t zhugeaming/user-thrift-service:latest . docker push zhugeaming/user-thrift-service:latest
Dockerfile
FROM java:openjdk-8 MAINTAINER liming www.idig8.com
COPY target/user-thrift-service-1.0-SNAPSHOT.jar /user-thrift-service.jar
ENTRYPOINT ["java","-jar","/user-thrift-service.jar"]
* 編寫(xiě)yml文件 使用docker stack 進(jìn)行批量生成
``` yml
version: "3.4"
services:
message-thrift-python-service:
image: zhugeaming/message-thrift-python-service:latest
deploy:
endpoint_mode: dnsrr
resources:
limits:
cpus: "0.2"
memory: "128M"
user-thrift-service:
image: zhugeaming/user-thrift-service:latest
deploy:
endpoint_mode: dnsrr
resources:
limits:
cpus: "0.2"
memory: "512M"
user-edge-service:
image: zhugeaming/user-edge-service:latest
deploy:
endpoint_mode: vip
resources:
limits:
cpus: "0.2"
memory: "512M"
ports:
- "8082:8082"
depends_on:
- user-thrift-service
- message-thrift-python-service
course-dubbo-service:
image: zhugeaming/user-edge-service:latest
deploy:
endpoint_mode: dnsrr
resources:
limits:
cpus: "0.2"
memory: "512M"
depends_on:
- user-thrift-service
course-edge-service:
image: zhugeaming/course-edge-service:latest
deploy:
endpoint_mode: vip
resources:
limits:
cpus: "0.2"
memory: "512M"
ports:
- "8081:8081"
depends_on:
- user-edge-service
gateway-zuul:
image: zhugeaming/gataway-zuul:latest
deploy:
endpoint_mode: vip
resources:
limits:
cpus: "0.2"
memory: "512M"
ports:
- "8080:8080"
depends_on:
- user-edge-service
- course-edge-service
networks:
default:
external:
name: idig8-overlay
docker stack 創(chuàng)建,因?yàn)闄C(jī)器內(nèi)存太小,我還是使用的外網(wǎng),下載鏡像有點(diǎn)慢。
docker stack deploy -c ms-service.yml ms
docker stack services ms
PS:創(chuàng)建成功,下一步就是調(diào)試微服務(wù)。
免責(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)容。