1、启动windows路由转发功能: 找到任务管理器 --》服务–》打开服务–》 ROUTing and Remote Access
2、关闭wsl中linux的防火墙
3、查看docker系统和linux系统的ip和网关
以下面为例
- # docker系统
- eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
- inet 10.88.0.5 netmask 255.255.0.0 broadcast 10.88.255.255
- inet6 fe80::d084:2bff:fef8:6f6c prefixlen 64 scopeid 0x20<link>
- ether d2:84:2b:f8:6f:6c txqueuelen 1000 (Ethernet)
- RX packets 11018 bytes 34987311 (33.3 MiB)
- RX errors 0 dropped 0 overruns 0 frame 0
- TX packets 9275 bytes 518234 (506.0 KiB)
- TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
-
-
- # linux系统
- eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
- inet 172.21.119.19 netmask 255.255.240.0 broadcast 172.21.127.255
- inet6 fe80::215:5dff:fe07:9deb prefixlen 64 scopeid 0x20<link>
- ether 00:15:5d:07:9d:eb txqueuelen 1000 (Ethernet)
- RX packets 15968042 bytes 23153227188 (21.5 GiB)
- RX errors 0 dropped 0 overruns 0 frame 0
- TX packets 2976761 bytes 261480455 (249.3 MiB)
- TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
4、在windows中添加路由信息
route add -P docker网段 mask docker子网掩码 Linux系统IP
(-P 长期生效,不加则机器重启后消失)
以上面为例 docker子网掩码为255.255.0.0 网段为10.88.0.0(注意网段,这很容易写错)
route add -P 10.88.0.0 mask 255.255.0.0 172.21.119.19
关于容器无法启动 Exited 139 错误
使用wsl2时,有些镜像太老,可以试下以下方法
1、在windows主机的%userprofile%文件夹下创建一个.wslconfig文件
- [wsl2]
- kernelCommandLine = vsyscall=emulate
2、cmd中执行 wsl --shutdown
3、重启docker