實(shí)現(xiàn)Docker跨主機(jī)間的容器網(wǎng)絡(luò)連通

Server1(Server) 192.168.81.58 |內(nèi)核版本 3.10.0-123.el7.x86_64 |Docker版本 1.12.6

Server2(Agent) ?192.168.81.59 ? ? ? ? ? ? ? ? ?3.10.0-123.el7.x86_64 ? ? ? ? ? ? ? ? ? ? 1.12.6

目標(biāo):實(shí)現(xiàn)兩個(gè)CentOS7容器server1,server2網(wǎng)絡(luò)互通

上傳docker_consul包c(diǎn)onsul_0.7.2_linux_amd64.zip

解壓consul并移動(dòng)到$PATH中

unzip consul_0.7.2_linux_amd64.zip -d /usr/local/bin

Server1:

mkdir /opt/d_c

nohup consul agent -server -bootstrap -data-dir /opt/d_c -bind=192.168.81.58 &

顯示結(jié)果:nohup: ignoring input and appending output to ‘nohup.out’

Server2:

mkdir /opt/d_c

nohup consul agent -data-dir /opt/d_c -bind=192.168.81.59 &

顯示結(jié)果:nohup: ignoring input and appending output to ‘nohup.out’

讓agent加入到server中

consul join 192.168.81.58

顯示結(jié)果:Successfully joined cluster by contacting 1 nodes.

vim /etc/sysconfig/docker-network

DOCKER_NETWORK_OPTIONS="-H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock --cluster-store consul://localhost:8500 --cluster-advertise eno16777736:2375"

service docker restart

docker network ls

顯示結(jié)果包含:multihost overlay global

查看Docker網(wǎng)絡(luò)內(nèi)的成員

consul members list

Server1:

docker run -d --net=multihost --name=web1 nginx

docker exec -it web1 /bin/bash

Server2:

docker run -d --net=multihost --name=web2 nginx

docker exec -it web2 /bin/bash

ping web1

ping web2

創(chuàng)建指定靜態(tài)IP的network

docker network create -d overlay --ip-range=192.168.2.0/24 --gateway=192.168.2.1 --subnet=192.168.2.0/24 multihost2

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容