mongodb run as docker container always gives the warning ‘vm.max_map_count is too low’ if I enter mongosh.
vm.max_map_count is set to 524288 in the host system permanently.
If I run ‘docker exec mongodb sysctl vm.max_map_count’ (mongodb is the container name) the result is
vm.max_map_count = 524288. So I assume the setting is replicated inside the container correctly.
Tried different values, different hosts (all ubuntu 22.04), always the same on every mongodb running in docker container. Restarting or recreating didn’t help.
If I run the mongod directly on the host, the warning is not shown.
Any ideas?
2
Answers
Thanks for putting me on the right track. Actually docker sets the soft limit to the hard limit of the host, which is too high. The soft limit seems to trigger the warning.
Since I'm running the container without docker-compose and portainer doesn't support all run options, I edited my daemon.json and added
which sets the limits for all containers.
Problem solved, thank you very much!
Each network connection requires 2 mapped virtual memory areas.
When mongod starts up, it checks the value from /proc/sys/vm/max_map_count to ensure it is at least double the maximum permitted number of inbound connections.
That warning is generated here:
https://github.com/mongodb/mongo/blob/master/src/mongo/transport/transport_layer_manager_impl.cpp#L223-L246
Specifically:
So there is no absolute value that triggers the warning, it is just pointing out to you that if your server actually tries to accept all of the connections allowed by net.maxIncomingConnections, it will not have enough maps, which will trigger as posix error, probably assertion failure, and possibly cause the mongod to crash.
If you think 524288 is enough maps, reduce the number of allowed incoming connections 262144 or less.