OpenWRT 中使用創(chuàng)建docker Openwrt和其他宿主機中的docker容器通信
網(wǎng)絡(luò)拓?fù)?/h3>
首先網(wǎng)絡(luò)得支持多撥,否則沒有意義,之所以這么折騰,是因為直接OpenWRT多撥的情況下,網(wǎng)心云從原先的映射公網(wǎng)型變成全錐型
openwrt主路由,
cpu:Intel? Celeron? CPU J1900 @ 1.99GHz
內(nèi)存:4G
網(wǎng)口:6口intel I211 千兆網(wǎng)口
原先計劃是PVE,然后跑4個OpenWRT虛擬機,然而帶不動,基本一天死機一回
后面改成現(xiàn)在這種模式:
局域網(wǎng)上網(wǎng)只用了0口和1口,有多余的網(wǎng)口用于docker openwrt
pve虛擬機跑docker 網(wǎng)心云
局域網(wǎng)劃分了4個網(wǎng)段
192.168.1.0/25 網(wǎng)關(guān)192.168.1.126
192.168.1.160/27 網(wǎng)關(guān)192.168.1.190
192.168.1.192/27 網(wǎng)關(guān)192.168.1.222
192.168.1.224/27 網(wǎng)關(guān)192.168.1.254
一、準(zhǔn)備
1、openwrt鏡像,
可以根據(jù)下面這個去擴容,原始鏡像的軟件空間太小了,版本自己下載最新的
https://blog.csdn.net/yuanmingming521/article/details/126741073
2、安裝pve
網(wǎng)上超多教程,這里就不寫了
替換國內(nèi)的源
vi /etc/apt/sources.list
#把其余的注釋掉
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian-security bullseye-security main contrib non-free
刪除PVE企業(yè)源
vi /etc/apt/sources.list.d/pve-enterprise.list
#注釋掉
#deb https://enterprise.proxmox.com/debian/pve stretch pve-enterprise
安裝docker
apt update
apt install docker.io
二、PVE配置
1、網(wǎng)絡(luò)配置
登錄pve
https://ip:8006
創(chuàng)建linux bridge
2、創(chuàng)建docker network
登錄PVE后臺,創(chuàng)建macvlan
docker network create -d macvlan --subnet=192.168.1.160/27 --gateway=192.168.1.190 -o parent=vmbr1 -o macvlan_mode=bridge net190
root@:~# docker network ls
NETWORK ID NAME DRIVER SCOPE
110ea0f854dc bridge bridge local
74e0f19ab3a1 host host local
dc7b6ee9f6c1 net190 macvlan local
3078d2dcba7c net222 macvlan local
0cf90f04cffa net254 macvlan local
4de979658c7e netlan macvlan local
3f03cc1590b4 netwan macvlan local
d861ece9492e none null local
root@:~#
三、OpenWRT配置
1、登錄openwrt,在網(wǎng)絡(luò)–>接口–>設(shè)備,添加設(shè)備配置
設(shè)備類型:選擇maclan
基設(shè)備:選擇對應(yīng)的物理網(wǎng)口
模式:橋接(允許mac vlan間直接通信)
其余默認(rèn)
2、配置接口ip
網(wǎng)絡(luò)–>接口–>添加新接口
名稱:br2(方便記憶,第二個網(wǎng)口)
協(xié)議:靜態(tài)IP或者不配置協(xié)議,我這里選擇的靜態(tài)ip
注意地址不要配置成網(wǎng)段的第一個可用ip,包括后面建立容器也一樣,不要使用第一個可用的ip
設(shè)備:選擇對應(yīng)的接口
點擊創(chuàng)建接口,配置相應(yīng)網(wǎng)段的空閑ip,wan口的macvlan 不配置ip
最后保存并應(yīng)用
根據(jù)上面的步驟創(chuàng)建其余的接口
3、創(chuàng)建docker network
登錄openwrt后臺,創(chuàng)建網(wǎng)絡(luò)
docker network create -d macvlan --subnet=192.168.1.160/27 --gateway=192.168.1.190 -o parent=eth2mac0 -o macvlan_mode=bridge net190
#下面這個網(wǎng)段隨便配置的
docker network create -d macvlan --subnet=192.168.100.0/24 --gateway=192.168.100.254 -o parent=eth1mac0 -o macvlan_mode=bridge netwan
eth2mac0 這個是連接pve的網(wǎng)口
eth1mac0 這是連接光貓的網(wǎng)口
4、創(chuàng)建docker OpenWRT
docker run --name op190 -d --network net190 --restart=always --privileged garethwang/openwrt-22.03.2-x86-64 /sbin/init
docker network connect netwan op190
5、修改OpenWRT的配置
5.1、修改docker openwrt的lan口ip
docker exec -it op190 sh
vi /etc/config/network
config interface 'lan'
option device 'br-lan'
option proto 'static'
option ipaddr '192.168.1.190'
option netmask '255.255.255.224'
option ip6assign '60'
ctrl+d
docker restart op190
5.2、登錄docker op190 配置網(wǎng)絡(luò)和安裝軟件
docker和宿主機是可以ping通的,但是電腦和docker在不同網(wǎng)段,ping不通,用xshell或者securecrt 登錄到openwrt主路由后,再跳轉(zhuǎn),
網(wǎng)頁輸入 127.0.0.1:2555,密碼是password
配置pppoe撥號上網(wǎng)
5.3、安裝必要的軟件
修改opkg 源
將上面位置的配置替換成如下的配置
src/gz openwrt_core https://mirrors.aliyun.com//openwrt/releases/22.03.2/targets/x86/64/packages/
src/gz openwrt_base https://mirrors.aliyun.com/openwrt/releases/22.03.2/packages/x86_64/base/
src/gz openwrt_luci https://mirrors.aliyun.com/openwrt/releases/22.03.2/packages/x86_64/luci/
src/gz openwrt_packages https://mirrors.aliyun.com/openwrt/releases/22.03.2/packages/x86_64/packages/
src/gz openwrt_routing https://mirrors.aliyun.com/openwrt/releases/22.03.2/packages/x86_64/routing/
src/gz openwrt_telephony https://mirrors.aliyun.com/openwrt/releases/22.03.2/packages/x86_64/telephony
然后安裝luci-i18n-base-zh-cn和luci-i18n-upnp-zh-cn,其他也不需要了
四、測試
在pve主機中創(chuàng)建容器
docker run -dit --name=wxy162 --net=net190 --ip=192.168.1.162 --privileged=true --tmpfs /run --tmpfs /tmp -v /mnt/wxy4/wxy4:/storage:rw registry.hub.docker.com/onething1/wxedge
進(jìn)入docker openwrt 去pingpve中的容器地址文章來源:http://www.zghlxwxcb.cn/news/detail-473886.html
root@OPHOME:~# docker exec -it op190 sh
BusyBox v1.35.0 (2022-10-14 22:44:41 UTC) built-in shell (ash)
/ # ping 192.168.1.162
PING 192.168.1.162 (192.168.20.162): 56 data bytes
64 bytes from 192.168.1.162: seq=0 ttl=64 time=0.571 ms
64 bytes from 192.168.1.162: seq=1 ttl=64 time=0.450 ms
64 bytes from 192.168.1.162: seq=2 ttl=64 time=0.449 ms
64 bytes from 192.168.1.162: seq=3 ttl=64 time=0.680 ms
^C
--- 192.168.1.162 ping statistics ---
4 packets transmitted, 4 packets received, 0% packet loss
round-trip min/avg/max = 0.449/0.537/0.680 ms
/ #
五、最終結(jié)果
文章來源地址http://www.zghlxwxcb.cn/news/detail-473886.html
到了這里,關(guān)于OpenWRT 中創(chuàng)建docker Openwrt和其他宿主機中的docker容器通信的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!