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.

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

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

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay