I'm experiencing extremely weak network performance when sending data from a host machine to a docker container, compared to traffic sent from a host machine to the same host.
I've measured the TCP performance using iPerf, these are the results on different operating systems with Docker installed:
Operating System | Client | Server | Bandwidth (measured with iPerf, see below) |
---|---|---|---|
macOS | Host | Host | ~56.3 Gbits/sec |
macOS | Host | Container | ~350 Mbits/sec |
Windows Pro 10 | Host | Host | ~5 Gbit/sec |
Windows Pro 10 | Host | Container | ~680 Mbit/sec |
The command run to get the results:
iperf -s -p 8020 # on the server side (receiving data)
iperf -c -p 8020 # on the client side (sending data)
I'm running the Docker containers in networking bridge mode (default) and publishing the port 8020 (network host mode is not available for macOS).
These results seem very unintuitive: First of all, on both operating system the measured bandwidth between a Docker container and the host machine falls drastically below the available bandwidth of a host-to-host-connection. Why is that? Afaik packets addressed to localhost are generally not handled by the NIC but rather by the OS/kernel itself, so they shouldn't depend on the NIC's available bandwidth. Although each Docker container uses its own network interface, I don't think the network card is involved there either (which could be a possible cause for a limited bandwidth/poor performance).
Secondly, it seems weird that the average bandwidth on Windows is higher than on macOS for host-to-container connections, even though we've achieved a much higher bandwidth on macOS for host-to-host connections.
Why on earth do we experience such a poor bandwidth for host-to-container packets? Is this a known issue with Docker containers (we couldn't find anything related to this on the internet that has the same results cross-platform)?Is there a good way to circumvent/fix this issue?