Docker vm.max_map_count 65530 is too low

Increase the limit of the mmap counts for Elasticsearch service.

Bootstrap checks failed due to max virtual memory areas vm.max_map_count [65530] is too low is a common issue.

$ sudo docker run --rm --name elasticsearch docker.elastic.co/elasticsearch/elasticsearch:8.2.3
{"@timestamp":"2022-06-23T20:50:59.580Z", "log.level": "INFO", "message":"version[8.2.3], pid[7], build[default/docker/9905bfb62a3f0b044948376b4f607f70a8a151b4/2022-06-08T22:21:36.455508792Z], OS[Linux/5.15.0-39-generic/amd64], JVM[Oracle Corporation/OpenJDK 64-Bit Server VM/18.0.1.1/18.0.1.1+2-6]", "ecs.version": "1.2.0","service.name":"ES_ECS","event.dataset":"elasticsearch.server","process.thread.name":"main","log.logger":"org.elasticsearch.node.Node","elasticsearch.node.name":"0495db0dbeec","elasticsearch.cluster.name":"docker-cluster"}
{"@timestamp":"2022-06-23T20:50:59.584Z", "log.level": "INFO", "message":"JVM home [/usr/share/elasticsearch/jdk], using bundled JDK [true]", "ecs.version": "1.2.0","service.name":"ES_ECS","event.dataset":"elasticsearch.server","process.thread.name":"main","log.logger":"org.elasticsearch.node.Node","elasticsearch.node.name":"0495db0dbeec","elasticsearch.cluster.name":"docker-cluster"}
[...]
ERROR: [1] bootstrap checks failed. You must address the points described in the following [1] lines before starting Elasticsearch.
bootstrap check failure [1] of [1]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
ERROR: Elasticsearch did not exit normally - check the logs at /usr/share/elasticsearch/logs/docker-cluster.log
[...]

The default limit of the mmap counts is definitely too low for Elasticsearch service.

$ sysctl vm.max_map_count
vm.max_map_count = 65530

Increase it to avoid running out of map areas.

$ echo "vm.max_map_count=262144" | sudo tee /etc/sysctl.d/90-max_map_count.conf
vm.max_map_count=262144
$ sudo sysctl --load /etc/sysctl.d/90-max_map_count.conf

Now, the container will start as expected.

$ sudo docker run --detach --name elasticsearch  --env "ELASTIC_PASSWORD=secret" \
                  docker.elastic.co/elasticsearch/elasticsearch:8.2.3
a67038f591a032d218ab03348e32a7f12e6c05cc5f9f346a7cb5ba441d5f63a7
$ sudo docker ps
CONTAINER ID   IMAGE                                                 COMMAND                  CREATED          STATUS                PORTS                                       NAMES
a67038f591a0   docker.elastic.co/elasticsearch/elasticsearch:8.2.3   "/bin/tini -- /usr/l…"   14 seconds ago   Up 14 seconds         9200/tcp, 9300/tcp                          elasticsearch

Determine elasticsearch IP address.

$ sudo docker inspect a67038f591a0  --format '{{ .NetworkSettings.IPAddress }}'
172.17.0.4

Check elasticsearch service.

$ curl --insecure -u elastic:secret https://172.17.0.4:9200/
{
  "name" : "a67038f591a0",
  "cluster_name" : "docker-cluster",
  "cluster_uuid" : "8A6Tz4hNTWu0o_QwGmOnqg",
  "version" : {
    "number" : "8.2.3",
    "build_flavor" : "default",
    "build_type" : "docker",
    "build_hash" : "9905bfb62a3f0b044948376b4f607f70a8a151b4",
    "build_date" : "2022-06-08T22:21:36.455508792Z",
    "build_snapshot" : false,
    "lucene_version" : "9.1.0",
    "minimum_wire_compatibility_version" : "7.17.0",
    "minimum_index_compatibility_version" : "7.0.0"
  },
  "tagline" : "You Know, for Search"
}

Docker vm.max_map_count 65530 is too low

Photo by Stefan Widua on Unsplash

Could You Please Share This Post? I Appreciate It And Thank YOU! :) Have A Nice Day!

SonarQube is the tool which allows developers to keep the clean code in their repositories. [ SonarQube Max virtual memory areas vm max_map_count 65530 ] It do automatic check every time when new code is pushed to the repository. If you haven’t started using this tool yet, then start! It will pay you back in the future.

Docker vm.max_map_count 65530 is too low
max_map_count

The system isn’t allowed to get the requested virtual memory amount.

In computing, virtual memory, or virtual storage[b] is a memory management technique that provides an “idealized abstraction of the storage resources that are actually available on a given machine”[3] which “creates the illusion to users of a very large (main) memory”

https://en.wikipedia.org/wiki/Virtual_memory

Solution

Run the following command before attempting to start Sonar or issuing your docker-composecommand:

# Set vm.max_map_count=262144

sudo sysctl -w vm.max_map_count=262144

max virtual memory areas vm.max_map_count 65530 is too low SonarQube

SonarQube Documentation

A self-managed, automated code review tool called SonarQube systematically aids in the production of Clean Code. SonarQube, a key component of our Sonar product, works with your current workflow to spot errors in your code and aids in your ongoing code inspection of your projects. To make sure your code complies with high standards, the tool analyzes 30+ different programming languages and interfaces with your CI pipeline and DevOps platform.

Writing Clean Code

A healthy codebase must be maintained by writing Clean Code. We refer to code that adheres to a stated standard as “Clean Code,” which includes being dependable, secure, manageable, legible, and modular in addition to other crucial characteristics. This is true for all types of code, including scripts, Infrastructure as Code, glue code, and source code.

Many of the difficulties that result from evaluating code at a late stage in the development process are eliminated by Sonar’s Clean as You Code methodology.

The Clean as You Code methodology leverages your Quality Gate to notify you when there is New Code (code that has been added or altered) that needs to be fixed or reviewed, allowing you to maintain high standards and concentrate on code quality.

SonarQube notifies your team that there are problems to fix using its UI, emails, and decorations on pull or merge requests (in commercial versions). When operating in Connected Mode, SonarLint may also provide feedback in IDEs that it supports.

For developers of all levels of expertise, SonarQube also offers in-depth help on the issues, explaining why each issue is a problem and how to remedy it. Code is only promoted when it passes the Quality Gate and is clean, so that developers may resolve problems in an efficient manner.

Could You Please Share This Post? 
I appreciate It And Thank YOU! :)
Have A Nice Day!
Docker vm.max_map_count 65530 is too low
YOU MIGHT ALSO LIKE