DEV Community

Dimitrios Desyllas
Dimitrios Desyllas

Posted on

How I can run elasticsearch locally for development using docker?

When I was running elastinc search using oficial docker images from docker hub: https://hub.docker.com/_/elasticsearch/

I used bind mounts at my docker-compose.yml:

version: '3.8' services: elasticsearch: image: elasticsearch:8.15.3 environment: - ES_JAVA_OPTS=-Xms512m -Xmx512m - discovery.type=single-node - xpack.security.enabled=false volumes: - ./volumes/elastic:/usr/share/elasticsearch/data ports: - "9200:9200" - "9300:9300" deploy: restart_policy: condition: always 
Enter fullscreen mode Exit fullscreen mode

That resulted that the mounted volume at /usr/share/elasticsearch/data having user ownership as root. Thus that made the elasticsearch to hand and terminate the container.

Therefore, I overrode the entrypoint using a Dockerfile:

FROM elasticsearch:8.15.3 COPY --chown=root:root --chmod=0755 ./entrypoint.sh /usr/local/bin/entrypoint.sh USER root ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] 
Enter fullscreen mode Exit fullscreen mode

And upon my custom entrypoint I call the existing one after I fix the nessesary file permissions:

#!/bin/bash ls -l /usr/share/elasticsearch mkdir -p /usr/share/elasticsearch/data chown -R elasticsearch:elasticsearch /usr/share/elasticsearch/data su -m elasticsearch /usr/local/bin/docker-entrypoint.sh "$@" 
Enter fullscreen mode Exit fullscreen mode

The idea is to launch the images entrypoint from my own one, as elasticsearch user after, as root first, fixed any permission upon my volumes.

Top comments (0)