在 Docker 中安装 OpenWRT (OneCloud, Ubuntu 22)
0. 更新 (Unnecessary 必需的)
你说的对, 但是
apt-get update && apt-get upgrade
是一款这可能会避免不必要的麻烦
apt-get install -y nano curl wget htop
1. 安装 Docker
懂得都懂
curl -fsSL https://get.docker.com | bash -s docker systemctl enable --now docker
reboot 一下
reboot
可能还需要额外执行
/usr/bin/dockerd -H unix:///var/run/docker.sock --bip=172.30.224.1/21 --ip-masq=false --mtu=1450 --containerd=/run/containerd/containerd.sock
2. 配置 Docker 网卡
确认你的 OneCloud 的内网 IP 地址, 使用以下命令快树地列出 OneCloud 上 eth0 网络接口的信息.
ifconfig | grep eth0 -A 10
你应该可以在输出里看到一个美丽的
inet 192.168.xxx.xxx
, 这个就是 OneCloud 的 IP 地址.我们现在假设他是
192.168.0.2
.配置你要在 Docker OpenWRT 中使用的虚拟网卡
docker network create -d macvlan --subnet=192.168.0.0/24 --gateway=192.168.0.1 --subnet=fe80:1::/64 --gateway=fe80:1::1 --ipv6 -o parent=eth0 macnet
不要乱填!
第一个
--gateway
参数的值更换成你实际网关的地址.一般来说就是你 OneCloud 连接上的路由器的 IP 地址.
第一个
--subnet
参数的值更换为你 OneCloud 的 IP 处在的网段.比如你 IP 为
192.168.5.114
这里就填写192.168.5.0/24
. 由于我们在上面假设 OneCloud 的 IP 为192.168.0.2
所以这里填写192.168.0.0/24
第二个
--subnet
和--gateway
是用于指定 IPv6 的, 要填写什么可以参考以上两条.这一部分可以照抄, 只不过只有 IPv6 出口没有入口.
提前配置一下容器内的网络
懂得都懂, 不懂的照抄
mkdir -p /home/docker/openwrt/
开始大配特配, 里面有注释说明的要修改, 其他的可以照抄
nano /home/docker/openwrt/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 packet_steering '1' config interface 'lan' option type 'bridge' option ifname 'eth0' option proto 'static' option netmask '255.255.255.0' option ip6assign '60' option ipaddr '192.168.0.114' ## 这里是你想要让这个容器独占的内网 IP 地址, 不要和你 OneCloud 的 IP 地址一样. 比如你上面 --subnet 写的 192.168.0.0/24 那就是 192.168.0.xxx, 如果 192.168.1.0/24 那就是 192.168.1.xxx, 以此类推 option gateway '192.168.0.1' ## 你的网关, 和上面设定的 --gateway 里面的一样 option dns '8.8.8.8' ## DNS, 随便找个顺手的即可 config interface 'vpn0' option ifname 'tun0' option proto 'none'
3. OpenWRT, 启动!
拉取镜像
docker run --restart unless-stopped --name="openwrt" -d --network macnet --privileged -v /home/docker/openwrt/network:/etc/config/network dreamwsbg/openwrt:11.0 /sbin/init
从
dreamwsbg/openwrt:11.0
Docker 镜像创建一个容器.我操, OP!
从浏览器访问你在 “3. 配置 Docker 网卡” 中的第三步中指定的容器 IP 地址, 按照示例是
192.168.0.114