与Docker容器共享虚拟网络 [英] Sharing virtual network with docker container
问题描述
我正在做一个项目,要求我在主机上创建虚拟CAN网络
I am working on a project that requires me to create a virtual CAN network on my host machine
$ sudo modprobe vcan
$ sudo ip link add dev vcan0 type vcan
$ sudo ip link set up vcan0
我的ifconfig:
My ifconfig :
我的问题是如何与Docker容器共享此接口。
My question is how can I share this interface with my docker container.
如果有任何用途,我运行以下命令 find / -name vcan0&; -print 2> / dev / null
在我的主机上:
If its of any use I ran the following command find / -name "vcan0" -print 2>/dev/null
on my host machine :
/sys/class/net/vcan0
/sys/devices/virtual/net/vcan0
/proc/sys/net/ipv4/conf/vcan0
/proc/sys/net/ipv4/neigh/vcan0
我可以使用 docker run --rm -it --network = host ...
。唯一的问题是不再有网络隔离黑白码头工人主机和容器。有没有一种方法可以实现上述目的,但不共享主机网络?
I can run the Docker container using docker run --rm -it --network=host ...
. The only problem is there is no network isolation b/w docker host and containers anymore. Is there a way to achieve the above but without sharing the host network ?
推荐答案
我还没有找到共享共享网络的方法。具有不带-network = host
的Docker容器的CAN网络接口,但是有可能的解决方法。您可以使用CAN-UDP桥接器,例如 canneloni 或 can2udp ,以通过UDP发送CAN帧。
I haven't found a way to share a CAN network interface with a Docker container without --network=host
, but there is a possible workaround. You can use a CAN-UDP bridge, like canneloni or can2udp, to send CAN frames over UDP.
我在过去将远程设备上的物理CAN总线连接到笔记本电脑上的虚拟CAN接口。
I've used this in the past to connect a physical CAN bus on a remote device to a virtual CAN interface on my laptop. But it should work just as well for a Docker container.
一个缺点是,您必须在Docker容器中创建 vcan
接口。容器。这要求您以特权模式运行容器。
One drawback is that you do have to create a vcan
interface in the container. Which requires you to run the container in privileged mode.
这篇关于与Docker容器共享虚拟网络的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!