opensearch-project / project-website

The source to opensearch.org
https://opensearch.org
BSD 3-Clause "New" or "Revised" License
40 stars 479 forks source link

[BUG] Suggested docker-compose.yml doesn't work with Docker Desktop for Windows, WSL2 mode #354

Open vivainio opened 3 years ago

vivainio commented 3 years ago

Describe the bug

In instructions stored at:

https://opensearch.org/downloads.html

It suggests to do this:

macOS & Windows: In Docker Preferences > Resources, set RAM to at least 4 GB.

However, this setting is not available in WSL2 mode.

When you do "docker-compose up", you get this error in the logs:

[1]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

There is no "easy" way to do this in Docker Desktop, in WSL2 mode.

To Reproduce

  1. Enable Docker Desktop WSL2 mode, as described in: https://docs.docker.com/desktop/windows/wsl/
  2. Download https://opensearch.org/samples/docker-compose.yml
  3. Do "docker-compose up" and follow the logs. You'll see that OpenSearch server crashes because of the error: " max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]"

Expected behavior

The example docker-compose.yml should work out of the box, also in Windows WSL2 mode. Possibly, there could be an environment variable to set that disables the initial check (allowing to at least test the application?)

Starting OpenSearch with environment variable discovery.type=single-node also avoids the crash

vivainio commented 3 years ago

The error is in no way particular to OpenSearch, it has been in ElasticSearch for a long time (see e.g. https://stackoverflow.com/questions/51445846/elasticsearch-max-virtual-memory-areas-vm-max-map-count-65530-is-too-low-inc). But maybe OpenSearch could finally fix it

dblock commented 3 years ago

@vivainio Want to suggest the preferred fix? Make a PR?

vivainio commented 3 years ago

@dblock I can't provide a preferred fix right away.

The "easy" fix would be to remove opensearch-node2 from docker-compose completely, and switch to discovery.type=single-node, but would that be too simple of a setup for demonstrating OpenSearch? Anyway, it would make it work on Windows after that

vivainio commented 3 years ago

Here's the contents of working docker-compose.yml that switches to "single-node" discovery type:

version: '3'
services:
  opensearch-node1:
    image: opensearchproject/opensearch:latest
    container_name: opensearch-node1
    environment:
      - cluster.name=opensearch-cluster
      - node.name=opensearch-node1
      - discovery.type=single-node
      - bootstrap.memory_lock=true # along with the memlock settings below, disables swapping
      - "OPENSEARCH_JAVA_OPTS=-Xms512m -Xmx512m" # minimum and maximum Java heap size, recommend setting both to 50% of system RAM
    ulimits:
      memlock:
        soft: -1
        hard: -1
      nofile:
        soft: 65536 # maximum number of open files for the OpenSearch user, set to at least 65536 on modern systems
        hard: 65536
    volumes:
      - opensearch-data1:/usr/share/opensearch/data
    ports:
      - 9200:9200
      - 9600:9600 # required for Performance Analyzer
    networks:
      - opensearch-net
  opensearch-dashboards:
    image: opensearchproject/opensearch-dashboards:latest
    container_name: opensearch-dashboards
    ports:
      - 5601:5601
    expose:
      - "5601"
    environment:
      OPENSEARCH_HOSTS: '["https://opensearch-node1:9200","https://opensearch-node2:9200"]'
    networks:
      - opensearch-net

volumes:
  opensearch-data1:

networks:
  opensearch-net:
dblock commented 3 years ago

Maybe someone else has an opinion about the best way to fix this? @peterzhuamazon?

Also, does this belong in opensearch-build repo?

peterzhuamazon commented 3 years ago

Just set this in your host machine I think WSL would work: sudo sysctl -w vm.max_map_count=262144

peterzhuamazon commented 3 years ago

This is something that is not a bug but a requirement since the days of ES on your host machine.

dblock commented 3 years ago

This is something that is not a bug but a requirement since the days of ES on your host machine.

Doesn't mean it's not a bug or it can't be improved! Doesn't feel like users should be doing extra work to get example setups going - they should "just work".

vivainio commented 3 years ago

@peterzhuamazon this is Windows host machine, not Linux. There are instructions for doing that on wsl that may or may not work. I essentially switched to trying the OpenSearch container image instead of ES container image because the WSL instructions at https://www.elastic.co/guide/en/elasticsearch/reference/current/docker.html#_set_vm_max_map_count_to_at_least_262144 stopped working

peterzhuamazon commented 3 years ago

@peterzhuamazon this is Windows host machine, not Linux. There are instructions for doing that on wsl that may or may not work. I essentially switched to trying the OpenSearch container image instead of ES container image because the WSL instructions at https://www.elastic.co/guide/en/elasticsearch/reference/current/docker.html#_set_vm_max_map_count_to_at_least_262144 stopped working

Hi @vivainio I am not very familiar with WSL. What is the outcome when you set this in shell? I thought WSL is hyperv running a Linux VM.

Please correct me if that is not the case. Curious to see what we can do to get it work on Windows.

Thanks.

AmiStrn commented 3 years ago

Would it be better if the failure would result in a single node cluster with an exception on adding the second node? The error message could suggest a fix in terms of required resources etc. Maybe a "loose" node number config stating that there should be x to y nodes and the result is a best effort between the min (x) and max (y)?

vivainio commented 3 years ago

@AmiStrn The problem is missing environment variable discovery.type=single-node, not necessarily the fact that there are two nodes.

@peterzhuamazon Docker Desktop WSL2 support installs a separate Linux distribution called "docker-desktop", that is used as the host. You would have to execute the command every time you boot your computer.

The fastest fix is probably to provide the docker-compose.yml file I provided above in the "getting started" guide, as the recommended alternative for Windows Docker Desktop users. I can provide it as PR if this is what the projects wants to do and the website is created from Github.

dblock commented 3 years ago

So this page https://opensearch.org/versions/opensearch-1-0-1.html would recommend a different .yml for Windows vs. not windows? Sounds like a good idea, wonder what @stockholmux has to say about it ...

Either way that belongs in https://github.com/opensearch-project/project-website which has the current .yml checked into samples, let's move this issue there?

peterzhuamazon commented 3 years ago

So this page https://opensearch.org/versions/opensearch-1-0-1.html would recommend a different .yml for Windows vs. not windows? Sounds like a good idea, wonder what @stockholmux has to say about it ...

Either way that belongs in https://github.com/opensearch-project/project-website which has the current .yml checked into samples, let's move this issue there?

Hi @dblock we also maintain a copy of dockercomposefile here: https://github.com/opensearch-project/opensearch-build/tree/main/release/docker/dockercomposefiles

If @stockholmux wants to make changes to the website we also need to add a copy for windows on build repo.

Thanks.

dblock commented 3 years ago

Let's move this to project-website @stockholmux.

elfisher commented 3 years ago

@AmiStrn The problem is missing environment variable discovery.type=single-node, not necessarily the fact that there are two nodes.

@peterzhuamazon Docker Desktop WSL2 support installs a separate Linux distribution called "docker-desktop", that is used as the host. You would have to execute the command every time you boot your computer.

The fastest fix is probably to provide the docker-compose.yml file I provided above in the "getting started" guide, as the recommended alternative for Windows Docker Desktop users. I can provide it as PR if this is what the projects wants to do and the website is created from Github.

@vivainio I like this approach. @stockholmux would it make sense to have this as an additional sentence at the top like "The best way to try out OpenSearch is to use Docker Compose. If you are on Windows, use this Docker Compose file. These steps will setup a two node cluster of OpenSearch plus OpenSearch Dashboards:"

Yury-Fridlyand commented 2 years ago

I run these commands before starting OpenSearch docker images (Win 11 + WSL2)

sudo swapoff -a
sudo sysctl -w vm.swappiness=1
sudo sysctl -w fs.file-max=262144
sudo sysctl -w vm.max_map_count=262144

Note: these config changes don't persist reboot.