Container to Container communication using nictype p2p

I’m wondering if it is possible to have two containers communicate exclusively with each other via p2p nictypes?

Ideally I want two containers to communicate via virtual ethernet interfaces, with as much performance as possible. The containers don’t need to communicate with the host OS, or with any external networks of interfaces on the host OS either.

Is using p2p nictypes this way possible? Is it a good idea?

I thought about using macvlan nictypes for the two containers, but I believe this needs a parent interface supplied… I also worry about the possibility of packets leaking in or out via the parent interface. I could always just attach the macvlan nictypes to an unused vlan (l2 frame tag), if this is the better performant option.

What are your thoughts?

It’s possible and I’ve done it before, you basically have the first container define a p2p nic with a fixed host_name.

Then the second container you set to use a physical nic with the parent being set to the host_name of the first container.

The only trick with this is that you need to make sure the second container starts after the first :slight_smile:

So say the first container has nictype=p2p name=eth0 host_name=p2p-c1, then your second container has nictype=physical name=eth0 parent=p2p-c1.

Now when the first container starts, p2p-c1 appears on the host system, then when the second starts, it takes that interface and makes it its eth0 interface in the container.

1 Like

Though depending on what you’re doing, an even faster alternative is to create a custom storage volume and attach it to both containers, then use unix sockets on that shared storage, so you don’t even use the network stack at all.

Thats also a good idea, I’ll keep that in mind for situations that don’t need a network stack!

Thats great, thanks for this response!
I can whip something up to control the sequence of how containers are brought up.

I’m wondering if you would consider the possibility of expanding the p2p nictype to more easily facilitate this? (just food for thought)