ElasticSearch in Windows docker image vm max map count
Asked Answered
S

13

38

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?

Stableman answered 8/2, 2017 at 11:13 Comment(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.Chicle
D
125

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!

Dux answered 14/9, 2020 at 10:14 Comment(5)
Saved me! only thig is, didn't work for me when ran that in CMD, but running that in PowerShell fixed the issue.Irishirishism
Saved me .. ThanksClayclaybank
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.Lavonda
Thank you very much, saved me hours of searchingFimbriation
Thanks, but this doesn't work after restartRoguery
F
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.

Fishy answered 29/5, 2020 at 3:14 Comment(5)
This worked for me as docker-machine ssh was not an option.Lodge
yeah, I forgot to mention that since I was dealing with WSL, docker-machine ssh wasn't an option either!Leisurely
Good answer people forget not everyone wants to use a different distro. I have Docker-Desktop with WSL 2 using DebianDutybound
Please use this commands wsl -d docker-desktop echo 262144 >> /proc/sys/vm/max_map_countRevelationist
Good Job 100% workingKanara
M
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://mcmap.net/q/111905/-using-docker-desktop-for-windows-how-can-sysctl-parameters-be-configured-to-survive-a-reboot

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

Manriquez answered 11/10, 2021 at 8:4 Comment(1)
And shutdown docker, shutdown wsl2 with wsl --shutdown, then start dockerBoadicea
V
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.

Valorous answered 30/12, 2020 at 11:59 Comment(1)
Hi, good answer, but is there anyway to keep this permanent? It seems I keep having to do this.Erna
C
6

You can set up vm.max_map_count using following commands:

docker-machine ssh

sudo sysctl -w vm.max_map_count=262144

Cytoplasm answered 20/9, 2017 at 17:59 Comment(2)
This works if you SSH into the docker-machine. I am doing this on Windows 7 with Docker toolbox(legacy requirement).Sherrard
What is wrong if my machine doesn't have the command docker-machine?Huddleston
R
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
Rumba answered 19/9, 2021 at 14:28 Comment(0)
I
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

Impregnable answered 8/2, 2017 at 20:41 Comment(0)
R
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

Redpencil answered 24/8, 2023 at 14:3 Comment(0)
S
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.

Stableman answered 13/2, 2017 at 9:59 Comment(1)
how/where did you find that?Leisurely
V
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

Vulnerary answered 7/4, 2021 at 11:46 Comment(2)
how to open such shell?Foliose
@Luck-Aron If you mean the shell, its windows terminal, if you mean the info, install and run neofetch bro.Vulnerary
A
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
Allergic answered 16/9, 2021 at 20:12 Comment(0)
A
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.

Apron answered 9/12, 2021 at 6:5 Comment(1)
better put into .wslconfig since wsl.conf will reset after reboot. like this: ` [wsl2] kernelCommandLine = "sysctl.vm.max_map_count=262144" ` learn.microsoft.com/en-us/windows/wsl/wsl-config#wslconfigMispronounce
P
-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

Persuader answered 11/9, 2020 at 7:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.