40

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?

1
  • 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. Commented Oct 24, 2020 at 13:45

13 Answers 13

130

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!

5
  • 4
    Saved me! only thig is, didn't work for me when ran that in CMD, but running that in PowerShell fixed the issue. Commented Mar 2, 2022 at 5:25
  • 1
    Saved me .. Thanks Commented Mar 31, 2022 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
    Commented Aug 25, 2022 at 8:46
  • 1
    Thank you very much, saved me hours of searching Commented Jul 23, 2023 at 0:43
  • Thanks, but this doesn't work after restart
    – frank
    Commented Jan 2 at 2:10
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.

5
  • 1
    This worked for me as docker-machine ssh was not an option.
    – Severin
    Commented Aug 16, 2020 at 11:11
  • 1
    yeah, I forgot to mention that since I was dealing with WSL, docker-machine ssh wasn't an option either! Commented Aug 18, 2020 at 3:28
  • 1
    Good answer people forget not everyone wants to use a different distro. I have Docker-Desktop with WSL 2 using Debian
    – Trevor
    Commented Apr 3, 2021 at 19:42
  • 2
    Please use this commands wsl -d docker-desktop echo 262144 >> /proc/sys/vm/max_map_count
    – Josh
    Commented Apr 7, 2021 at 16:14
  • Good Job 100% working
    – user2447290
    Commented Sep 28, 2022 at 6:56
10

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

1
  • 1
    And shutdown docker, shutdown wsl2 with wsl --shutdown, then start docker
    – Max
    Commented May 26, 2023 at 9:07
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.

1
  • 2
    Hi, good answer, but is there anyway to keep this permanent? It seems I keep having to do this. Commented Jul 15, 2021 at 17:08
6

You can set up vm.max_map_count using following commands:

docker-machine ssh

sudo sysctl -w vm.max_map_count=262144

2
  • This works if you SSH into the docker-machine. I am doing this on Windows 7 with Docker toolbox(legacy requirement).
    – Namphibian
    Commented Oct 2, 2019 at 0:51
  • What is wrong if my machine doesn't have the command docker-machine?
    – Jolta
    Commented Oct 6, 2021 at 7:01
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
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

2

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

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.

1
  • how/where did you find that? Commented May 28, 2020 at 21:32
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

2
  • how to open such shell?
    – Luk Aron
    Commented Nov 7, 2021 at 9:54
  • @Luck-Aron If you mean the shell, its windows terminal, if you mean the info, install and run neofetch bro.
    – Jay
    Commented Nov 8, 2021 at 12:55
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
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.

1
-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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.