Docker image remove while rebuilding app

AI-generated summary

Docker Image Removal while Rebuilding App

The discussion revolves around removing Docker images while rebuilding an app. Hitesh_Sharma inquires about running docker image prune -a --force or ./launcher cleanup in the app.yml or launcher file.

Merefield suggests running ./launcher cleanup app before rebuilding, but advises against running these commands during a rebuild due to potential safety issues. Instead, they recommend using a bash script to run the commands in series.

Hitesh_Sharma shares their experience of creating a custom bash script that rebuilds the app and removes unused Docker images. However, they encountered issues when trying to add the commands to the app.yml or launcher file, resulting in the removal of all images. To resolve this, they added a filter to the command: docker image prune -a --force --filter "until=240h".

Pfaffman questions the purpose of removing Docker images during a rebuild, warning that it can be dangerous if something goes wrong. They emphasize that the commands cannot be executed inside the container, but rather in a shell script that runs the launcher.

Can we use the docker container remove command while rebuilding the app under the app.yml file or launcher file?

docker image prune -a --force

or

./launcher cleanup

if you have any idea about this please answer this query

thank you in advance :grinning:

You can run ./launcher cleanup app first to remove all stopped containers.

You normally run this before rebuilding whilst the latest container is still running.

Hi @merefield

these commands it is working for me ./launcher cleanup app but I actually add these command in the app.yml file or launcher files

I’m using just one command: ./launcher rebuild app. Can I put these commands in the files I mentioned earlier?

The fact that that’s never recommended leads me to think that running that command during a rebuild might not work/be safe.

You could try running them in series in a bash script?

You could try running them in series in a bash script?

I already created a custom bash script for rebuilding the app and after rebuilding done then removed unused docker images from a discourse docker container

However, I’m interested in knowing whether these commands can be added to the app.yml file or the launcher file.

I experimented with them on the staging site once but encountered an issue in the launcher file. While the commands work for me, using them results in the removal of all images.
docker image prune -a --force

To address this, I incorporated a filter for the last 24 hours in the command:
docker image prune -a --force --filter "until=240h" and this solution is effective for me.

What problem are you trying to solve? You have to little disk space to build a container without deleting the old one? It’s dangerous since it’s something goes wrong you are dead in the water.

You cannot do it in launcher since those commands are executed inside the container. You can do it in a shell script that would do that and run launcher.