37

I am new to Docker and Elasticsearch. I am using a Windows 7 machine. I am using docker-compose up to bring up the docker container. My yml file has

elasticsearch:
  image: elasticsearch:5.1.1
  environment:
    ES_JAVA_OPTS: "-Xms1g -Xmx1g"

along with other linked images.
I am using docker to bring up the elasticsearch image and when I do so I get the following error

[36melasticsearch_1   |←[0m ERROR: bootstrap checks failed
[36melasticsearch_1   |←[0m max virtual memory areas vm.max_map_count [65530]  is too low, increase to at least [262144]
[36melasticsearch_1   |←[0m [2017-02-08T11:06:51,752][INFO ][o.e.n.Node

I googled for a solution and everywhere they suggest to use sudo sysctl vm.max_map_count=262144, but in Windows sysctl is not available. No clear steps are given for Windows.

Some other Docker images are up and running on my machine so Docker is working.

Can someone give any clues to solve this issue?

Davide Fiocco
  • 5,350
  • 5
  • 35
  • 72
Anantha Krishnan
  • 501
  • 1
  • 4
  • 7
  • 1
    Thanks for asking this question. I found the answer in one of the suggestions below. You might save people time in the future if you tick the right answer. – Steve Tomlin Oct 24 '20 at 13:45

13 Answers13

114

I have been stuck for months on this problem, the solution is launch the following commands on cmd.exe (try Powershell or Bash if cmd doesn't work), as stated in the official Elasticsearch documentation:

1) wsl -d docker-desktop
2) sysctl -w vm.max_map_count=262144

And you are ready to start Elasticsearch!

Paolo De Dominicis
  • 1,255
  • 1
  • 9
  • 10
  • 3
    Saved me! only thig is, didn't work for me when ran that in CMD, but running that in PowerShell fixed the issue. – Talkhak1313 Mar 02 '22 at 05:25
  • 1
    Saved me .. Thanks – Sunny Tambi Mar 31 '22 at 10:58
  • If `wsl -d docker-desktop` does not bring you into the docker-desktop subsystem, you will be prompt `sysctl` is not found when you execute the second command. In this case, try uncheck "Use the WSL 2 based engine" in the docker desktop app and then check it again. – Yuefeng Li Aug 25 '22 at 08:46
  • 1
    Thank you very much, saved me hours of searching – Asaad Mamoun Jul 23 '23 at 00:43
21

Currently, following this issue, the way to make it work is by wsl -d docker-desktop and sysctl -w vm.max_map_count=262144 there.

Some people got it to work persistently by echo "vm.max_map_count = 262144" > /etc/sysctl.d/99-docker-desktop.conf or echo -e "\nvm.max_map_count = 262144\n" >> /etc/sysctl.d/00-alpine.conf, but none of these worked for me.

João Ciocca
  • 776
  • 1
  • 10
  • 23
9

the only thing that worked for me as permanent solution was adding this line to the .wslconfig (should be in your windows user directory %userprofile%)

[wsl2]
kernelCommandLine="sysctl.vm.max_map_count=262144"

thanks to @NotTheDr01ds for finding the solution

https://stackoverflow.com/a/69294687/1972133

https://learn.microsoft.com/en-us/windows/wsl/wsl-config#wslconfig

NanoNova
  • 829
  • 10
  • 19
mukki182
  • 115
  • 1
  • 5
8

Elasticsearch have a fix for this.

This worked for me on Win 10 Pro Version 10.0.19042.685, Docker Engine v20.10.0 Using ES 7.10

The problem is on the host linux machine (WSL2) not the containers.

see section Windows with Docker Desktop WSL 2 backend https://www.elastic.co/guide/en/elasticsearch/reference/current/docker.html#_set_vm_max_map_count_to_at_least_262144

-d distribution (eg not ubuntu)

wsl -d docker-desktop
sysctl -w vm.max_map_count=262144

After that my 3 node cluster docker-compose launched successfully.

JohnC
  • 2,687
  • 1
  • 22
  • 30
6

You can set up vm.max_map_count using following commands:

docker-machine ssh

sudo sysctl -w vm.max_map_count=262144

3

I tried all the approaches and non worked for me... However I was able to set it permanently like this.

  1. Create a bat file for example (set_vm_max.bat)
  2. Write the command inside the file "wsl -d docker-desktop sysctl -w vm.max_map_count=262144"
  3. Now will have to copy the file to the startup location, press "Windows + R"
  4. Type "shell:startup" and press Enter.
  5. Copy the file you just created to start location.

To verify it works:

  1. Reboot
  2. wsl -d docker-desktop
  3. cat /proc/sys/vm/max_map_count
Lucasz
  • 1,150
  • 9
  • 19
Rsokolov
  • 53
  • 1
  • 6
2

You started Elasticsearch in normal or production mode, which from Version 5 contains bootstrap checks, and if they fail Elasticsearch won't start.

https://www.elastic.co/guide/en/elasticsearch/reference/current/bootstrap-checks.html

However you can run the development mode on Windows, which only resolves into warnings. Just try to run the image of elastic itself.

docker run -p 9200:9200 -e "http.host=0.0.0.0" \
 -e "transport.host=127.0.0.1" \
 docker.elastic.co/elasticsearch/elasticsearch:5.2.0

https://www.elastic.co/guide/en/elasticsearch/reference/current/docker.html

cinhtau
  • 1,002
  • 8
  • 16
1

As I was new to this Docker I am confused with the basics. I found the solution for my problem now. In the docker installed in windows there is an Oracle VM Linux box created. I opened that and then there I added the sudo sysctl vm.max_map_count=262144 after which the problem was solved.

Martín Schonaker
  • 7,273
  • 4
  • 32
  • 55
Anantha Krishnan
  • 501
  • 1
  • 4
  • 7
1

Unintentionally found that simpler solution for wsl2 user, just run following command in your default wsl2 distribution shell

sudo sysctl -w vm.max_map_count=262144

for example:

enter image description here

Jay
  • 738
  • 8
  • 14
1

In Docker Desktop

wsl -d docker-desktop
sysctl -w vm.max_map_count=262144

In Rancher Desktop

wsl -d rancher-desktop
sysctl -w vm.max_map_count=262144

Rancher with provisioning scripts

Frank Escobar
  • 648
  • 5
  • 15
0

The following answer suggested in one of the comments worked well (persisted until machine reboot) in Windows 10, WSL2:

wsl -d docker-desktop
echo 262144 >> /proc/sys/vm/max_map_count
YakovK
  • 337
  • 2
  • 10
0
  • wsl -d docker-desktop
  • vi /etc/wsl.conf

add these lines at the end:

[boot]
kernelCommandLine = "sysctl.vm.max_map_count=262144"

Then restart docker-desktop.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Wp.
  • 21
  • 3
  • better put into `.wslconfig` since `wsl.conf` will reset after reboot. like this: ` [wsl2] kernelCommandLine = "sysctl.vm.max_map_count=262144" ` https://learn.microsoft.com/en-us/windows/wsl/wsl-config#wslconfig – NanoNova May 16 '23 at 09:14
-1

Elasticsearch required minimal value 262144 for variable vm.max_map_count.

In linux, show variable value:

sysctl --values vm.max_map_count

Change variable value:

sudo sysctl --w vm.max_map_count=262144

Learn more at Elastisearch guide