The Elasticsearch documentation on setting vm.max_map_count=262144 in a docker container doesn't seem to work. The only way I could get this to work was to mount a volume on the host that contained a sysctl.conf file to an /etc directory in the container. See below for the Elasticsearch block in docker-compose.yml. The host contains a directory path of ./mountpoints/etc. Inside the host's etc/directory is a sysctl.conf file which contains one line:
vm.max_map_count=262144
This is shared with the container inside the container's /etc directory.
Note also the environment setting
discovery.type=single-node
This is required but (IMO) not very clear in the documentation. If you don't include this, the stupid container will keep waiting for other nodes to join. Why the single node setup isn't the default behavior, I don't know.
elasticsearch:
image: "docker.elastic.co/elasticsearch/elasticsearch-7.9.3
container name: "elastic"
environment:
- discovery.type=single-node
volumes:
- type: volume
source: elastic
target: /usr/share/elasticsearch/data
- './mountpoints/etc/:/etc/'
ports:
- target: 9200
published: 9200
networks:
- localnet