armbian下安装Docker OpenWrt旁路由(未完成)
背景
初体验
获取镜像
openwrt镜像
docker pull unifreq/openwrt-aarch64
或者 (x86-64环境下)
docker pull openwrtorg/rootfs:x86-64
docker管理面板镜像
docker pull portainer/portainer:linux-arm64
或者 (x86-64环境下)
docker pull portainer/portainer
如果不熟悉portainer的话,可以先看看portainer的在线demo地址:
地址: http://demo.portainer.io/
用户名: admin
密码: tryportainer
启动portainer镜像
先创建volume
docker volume create portainer_data
结果
# ls -ld /var/lib/docker/volumes/portainer_data/
drwxr-xr-x 3 root root 4096 Apr 27 23:14 /var/lib/docker/volumes/portainer_data/
再启动镜像
docker run -d --name=portainer -p 9000:9000 -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer:linux-arm64
或者 x86 下
docker run -d --name=portainer -p 9000:9000 -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer
用浏览器访问9000端口即可。
创建docker网络
由于在做路由器,因此需要两个网卡。这里虚拟出来一块网卡。
docker network create -d macvlan --subnet=192.168.12.0/24 -o parent=eth0 macvlan
结果
# docker network ls | grep macvlan
61d44abcff0e macvlan macvlan local
# docker network inspect macvlan
[
{
"Name": "macvlan",
"Id": "61d44abcff0ef4ff7286b7525f5211b0bc89adc290f1110ca399025379dacc77",
"Created": "2020-05-02T21:16:00.687237222+08:00",
"Scope": "local",
"Driver": "macvlan",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": {},
"Config": [
{
"Subnet": "192.168.12.0/24"
}
]
},
"Internal": false,
"Attachable": false,
"Ingress": false,
"ConfigFrom": {
"Network": ""
},
"ConfigOnly": false,
"Containers": {},
"Options": {
"parent": "eth0"
},
"Labels": {}
}
]
创建OpenWrt容器
docker run -d --name=OpenWrt --restart always --network macvlan --privileged unifreq/openwrt-aarch64:latest
查看网络配置
# docker exec OpenWrt ifconfig
br-lan Link encap:Ethernet HWaddr 02:42:C0:A8:0C:02
inet addr:192.168.1.1 Bcast:192.168.1.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:25 errors:0 dropped:0 overruns:0 frame:0
TX packets:53 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:3237 (3.1 KiB) TX bytes:8550 (8.3 KiB)
eth0 Link encap:Ethernet HWaddr 02:42:C0:A8:0C:02
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:25 errors:0 dropped:0 overruns:0 frame:0
TX packets:54 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:3587 (3.5 KiB) TX bytes:9593 (9.3 KiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:41 errors:0 dropped:0 overruns:0 frame:0
TX packets:41 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:5229 (5.1 KiB) TX bytes:5229 (5.1 KiB)
这里的192.168.1.1
是不对的,我们进入docker来设置成对的。
docker exec -it OpenWrt bash
修改文件/etc/config/network
如下:
config interface 'loopback'
option ifname 'lo'
option proto 'static'
option ipaddr '127.0.0.1'
option netmask '255.0.0.0'
config globals 'globals'
option ula_prefix 'fd5c:382d:eff9::/48'
config interface 'lan'
option type 'bridge'
option ifname 'eth0'
option proto 'static'
option ipaddr '192.168.31.3'
option netmask '255.255.255.0'
option gateway '192.168.31.1'
option dns '192.168.31.1'
option ip6assign '60'
config interface 'vpn0'
option ifname 'tun0'
option proto 'none'
重启网络
/etc/init.d/network restart
确认生效
ifconfig br-lan
br-lan Link encap:Ethernet HWaddr 02:42:C0:A8:0C:02
inet addr:192.168.12.1 Bcast:192.168.12.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:25 errors:0 dropped:0 overruns:0 frame:0
TX packets:49 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:4759 (4.6 KiB) TX bytes:7469 (7.2 KiB)
重启OpenWrt容器
docker restart OpenWrt
再次确认生效
docker exec OpenWrt ping 192.168.31.1
PING 192.168.31.1 (192.168.31.1): 56 data bytes
64 bytes from 192.168.31.1: seq=0 ttl=64 time=0.559 ms
docker exec OpenWrt ping www.baidu.com
PING www.baidu.com (182.61.200.7): 56 data bytes
64 bytes from 182.61.200.7: seq=0 ttl=54 time=4.527 ms
进入OpenWrt设置
浏览器访问
后台:192.168.31.2
用户:root
密码:password