I would like to set the UDP buffer size for a docker container. Though, the UDP buffer size is a setting related to the kernel and it corresponds to that of the host, I see that, I don't see my host setting of the buffer size affecting my container.
Here is what I have tried:
On host
sysctl -w net.core.rmem_default = 4194304
sysctl -w net.core.rmem_max = 4194304
and to verify (on host)
sysctl net.core.rmem_default
net.core.rmem_default = 4194304
sysctl net.core.rmem_max
net.core.rmem_max = 4194304
But, when I run in the container (say alpine).
docker run -it alpine
and in alpine ash
sysctl net.core.rmem_default
sysctl: error: 'net.core.rmem_default' is an unknown key
The same is the case with rmem_max also.
However, to my surprise, I see
sysctl net.core.rmem_default
net.core.somaxconn = 128
I am able to set the above on docker container using --sysctl argument.
docker run -it --sysctl net.core.somaxconn=125 alpine
/ # sysctl net.core.somaxconn
net.core.somaxconn = 125
But, what I need is rmem_default and rmem_max sizes.
If this option is not provided through --sysctl flag and that the setting depends on the host machine, then
How can I prove that the buffer size on the container is same as that of the host?
Moreover, during many tests, I came to know that the packets are being dropped (I think, it is because of some low buffer size being set).
I also tried writing to the /proc/sys/net/core/rmem_default in the container but I got cannot stat error. I did not understand why there is no such file as rmem_default and the like (rmem_max etc) which are found on the host in the docker /proc.
I have heard that the host /proc is mounted on the container. Is it true? It doesn't seem to be considering the above scenario.
Also, editing the sysctl.conf and calling sysctl -p also did not help.
Feel free to move this question to unix.stackexchange.com if it makes sense there.
Your main problem is that those values are not namespaced, that means they are shared between all network namespaces. There is a kernel patch in state RFC since 2017 which wants to make them namespaced: [RFC] net: make net.core.{r,w}mem_{default,max} namespaced
This patch alone would not allow you to use them within a kubernetes pod. You would need to allow the sysctls like described in Using sysctls in a Kubernetes Cluster
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With