Skip to content
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 GitHub? Sign in to your account

Add cleanup script #123

Open
sdavids opened this issue Dec 21, 2023 · 3 comments
Open

Add cleanup script #123

sdavids opened this issue Dec 21, 2023 · 3 comments

Comments

@sdavids
Copy link

sdavids commented Dec 21, 2023

Hi,

please add a cleanup script to your repo.

After finishing the course one should be able to easily get rid of everything.

The easiest way would be to label all your images, volumes, and networks.


Open Container Initiative - Pre-Defined Annotation Keys

Dockerfile - LABEL
Compose file / Networks / labels
Compose file / Volumes / labels
Compose file / Services / labels


Dockerfile

LABEL org.opencontainers.image.vendor="io.diveinto"

docker-compose.yml

networks:
  diveinto.io:
    name: diveinto.io
    labels:
      org.opencontainers.image.vendor: io.diveinto

You currently use anonymous volumes, so you might want to convert them to named volumes with a label and/or you might want to update your README:

docker-compose rm

docker-compose rm -v

docker compose rm / options


Instead of (in addition to) org.opencontainers.image.vendor you might want to use your own label io.diveinto.docker.group="diveintoansible-lab" for example.


This is how the cleanup script could look like:

#!/usr/bin/env sh

set -eu

readonly label="org.opencontainers.image.vendor=io.diveinto"

docker-compose rm -v

docker container prune --force --filter="label=${label}"

docker volume prune --force --all --filter="label=${label}"

docker image prune --force --all --filter="label=${label}"

docker network prune --force --filter="label=${label}"

docker image prune - filtering

@spurin
Copy link
Owner

spurin commented Dec 21, 2023

Thanks for your feedback and insight @sdavids - appreciated.

We use host volume mounts for persistence and the ability to edit files locally, that said though it's not used that often even though it's a feature.

I've been considering removing this and may switch to standard volumes. This is the only variable for me in this feedback, the rest of it are logical improvements.

Again, thanks for your input on this

@mvtab
Copy link

mvtab commented Aug 14, 2024

I know it's not optimal, but since the only problems are the images and local volumes, you can cleanup like this, while the compose setup is running and you are in the lab root directory:

DIVEINTO_IMAGES=$(docker compose images -q)
docker compose down
docker rmi ${DIVEINTO_IMAGES}
rm -rf ./ansible_home

This will delete all the related images and all the local volumes of the lab. Save your data first, if needed.

@spurin
Copy link
Owner

spurin commented Aug 15, 2024

Love that approach! It's slick 🙏

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

No branches or pull requests

3 participants