8000 Added the prune of docker images when uninstall by ezimuel · Pull Request #59 · elastic/start-local · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Added the prune of docker images when uninstall #59

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHu 10000 b? Sign in to your account

Merged
merged 5 commits into from
Jun 6, 2025
Merged

Conversation

ezimuel
Copy link
Collaborator
@ezimuel ezimuel commented Jun 5, 2025

This PR implements the #56 proposal. It adds this questions when running uninstall.sh script:

Do you want to remove the following Docker images?
- docker.elastic.co/elasticsearch/elasticsearch:9.0.2
- docker.elastic.co/kibana/kibana:9.0.2
Do you confirm? (yes/no)

If confirm is yes the script execute the following commands:

docker rmi docker.elastic.co/elasticsearch/elasticsearch:9.0.2
docker rmi docker.elastic.co/kibana/kibana:9.0.2

The docker disk images of Elasticsearch and Kibana 9.0.2 is about 2.6 GB.

@ezimuel ezimuel requested a review from flobernd June 5, 2025 20:10
ezimuel and others added 3 commits June 6, 2025 08:04
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Copy link
Member
@flobernd flobernd left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for implementing this feature 🙂

Left a minor comment for discussion.

start-local.sh Outdated

cat >> uninstall.sh <<- EOM
if ask_confirmation; then
docker rmi docker.elastic.co/elasticsearch/elasticsearch:${es_version}
Copy link
Member

Choose a reason for hiding this comment

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

Just some thoughts regarding a potential unhappy path: If the user has any other container that still actively uses the image, this command will fail.

I can imagine different strategies:

  1. This should be a rare case, let's not do anything. The user might have to prune the image manually for the kibana image, since the script will exit early at this point.
  2. Change to docker rmi ... || true to allow the script to continue and try to at least prune the kibana image (if that's not in use as well).
  3. Proactively check, if the image is still in use before attempting to remove it (e.g. if [ -n "$(docker ps -a --filter ancestor=docker.elastic.co/elasticsearch/elasticsearch:${es_version} --format '{{.ID}}')" ]; then)

Personally I would go with the 2. approach since this one:

  • Makes the best possible effort to remove all images, even if the removal of one image fails
  • It's simple
    • No additional custom logic in start-local.sh
    • Standard Docker error message on failure

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think 2 or 3 are valid options. Let me try with 3, I like the idea of checking before and if the image is already in use in other services I can even skip the question.

Copy link
Member

Choose a reason for hiding this comment

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

Sounds good!

@ezimuel
Copy link
Collaborator Author
ezimuel commented Jun 6, 2025

@flobernd I actually proposed a different approach. I check the execution of each docker rmi command using the following approach:

if docker rmi "docker.elastic.co/elastic...:${es_version}" >/dev/null 2>&1; then
  echo "Image docker.elastic.co/elastic...:${es_version} removed successfully"
else
  echo "Failed to remove image docker.elastic.co/elastic...:${es_version}. It might be in use."
fi

In this way I don't need to change the execution flow and I manage all the use cases.

@ezimuel ezimuel merged commit 230ffce into main Jun 6, 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.

2 participants
0