Docker image remove while rebuilding app

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.

2 Likes