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.

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay