Skip to content

Added ES_LOCAL_DIR env variable#65

Merged
ezimuel merged 4 commits intomainfrom
add-es-local-dir-env
Jul 7, 2025
Merged

Added ES_LOCAL_DIR env variable#65
ezimuel merged 4 commits intomainfrom
add-es-local-dir-env

Conversation

@ezimuel
Copy link
Copy Markdown
Collaborator

@ezimuel ezimuel commented Jul 1, 2025

This PR adds the ES_LOCAL_DIR environment variable to change the installation folder name (default is elastic-start-local).
You can specify this ENV variable as follows:

curl -fsSL https://elastic.co/start-local | ES_LOCAL_DIR="myfolder" sh

This PR implements the request in #62.

Copy link
Copy Markdown
Member

@pquentin pquentin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! While this changes the directory name, it does not close #62 as it does not change the container names:

# Elasticsearch container name
elasticsearch_container_name="es-local-dev"
# Kibana container name
kibana_container_name="kibana-local-dev"

I'm getting the following error when trying it with an instance of start-local already running:

The docker container 'es-local-dev' is already running!
You can have only one running at time.
To stop the container run the following command:

@ezimuel
Copy link
Copy Markdown
Collaborator Author

ezimuel commented Jul 2, 2025

@pquentin this is the expected behaviour since we want to have only one Elasticsearch instance running at time. Changing the folder name allows having multiple installations, since we can have different volume name (docker uses the folder name as prefix for the volume).

Copy link
Copy Markdown
Member

@pquentin pquentin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While you can have different installations, you still need to manually docker rm all containers, otherwise you get:

Error response from daemon: Conflict. The container name "/es-local-dev" is already in use by container "e4d9fb3587bcb97d50daec85144ae2c22189127323a3c6c5a33644156582b1e1". You have to remove (or rename) that container to be able to reuse that name.

Using different names would avoid this problem (but not the port collision). Since you're saying this is by design, I'm approving as the functionality works.

@bejean
Copy link
Copy Markdown

bejean commented Jul 2, 2025

@ezimuel
After creating and starting a new stack than stopping it with ./stop.sh, it is not possible to create and start a new stack due to container name conflict.
stop.sh scipt shoud remove the container by performing "down" command instead "stop"
In start-local.sh script, it works if you change the lines
docker_stop=...

@ezimuel
Copy link
Copy Markdown
Collaborator Author

ezimuel commented Jul 2, 2025

@bejean , @pquentin I think you right. I need to change the approach here. Thanks for the feedback!

@ezimuel
Copy link
Copy Markdown
Collaborator Author

ezimuel commented Jul 4, 2025

@pquentin and @bejean I just updated the PR adding ES_LOCAL_DIR in all the docker service names. This should fix the issue.

Copy link
Copy Markdown
Member

@pquentin pquentin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works well, thank you! I've added two nitpicks that you can ignore.

start-local.sh Outdated
elasticsearch_container_name="es-local-dev-${ES_LOCAL_DIR:-}"
# Kibana container name
kibana_container_name="kibana-local-dev"
kibana_container_name="kibana-local-dev-${ES_LOCAL_DIR:-}"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be named ES_LOCAL_DIR? It is consistent with ES_LOCAL_VERSION which also applies to Kibana, so that's good.

Still, when I see ES I think about Elasticsearch, so something like ELASTIC_STACK_LOCAL_DIR would be more descriptive but also more verbose.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason for choosing ES_LOCAL_DIR was to be consistent with the existing settings. The ES_LOCAL_VERSION is used also in Kibana since the version must be the same. If you want ES can be think as Elastic Stack, rather than only Elasticsearch 😄

start-local.sh Outdated
min_docker_compose="1.29.0"
# Elasticsearch container name
elasticsearch_container_name="es-local-dev"
elasticsearch_container_name="es-local-dev-${ES_LOCAL_DIR:-}"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to avoid the dash when no local directory is set? This is what most users will see:

 ✔ Container es-local-dev-            Healthy
 ✔ Container kibana-settings-         Exited
 ✔ Container kibana-local-dev-        Healthy

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! I removed the dash at the end with this syntax:

  elasticsearch_container_name="es-local-dev${ES_LOCAL_DIR:+-${ES_LOCAL_DIR}}"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! The only difference now is that docker rm fails on uninstall.sh but that's OK as the script still uninstalls correctly.

Do you want to remove the following Docker images?
- docker.elastic.co/elasticsearch/elasticsearch:9.0.3-arm64
- docker.elastic.co/kibana/kibana:9.0.3-arm64
Do you confirm? (yes/no)
yes
Failed to remove image docker.elastic.co/elasticsearch/elasticsearch:9.0.3-arm64. It might be in use.
Failed to remove image docker.elastic.co/kibana/kibana:9.0.3-arm64. It might be in use.
Start-local successfully removed

Copy link
Copy Markdown
Member

@pquentin pquentin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for iterating! LGTM.

@ezimuel ezimuel merged commit e3355cb into main Jul 7, 2025
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants