My solution is definitely more aggressive but works. Just execute the following bash script after each docker-compose up -d. You could also run this on a schedule using crontab.
The script below essentially just finds any containers with “clamd” and “solr” as string in the name, and does 3 things:
1) Updates container restart policy to OFF (optional and useful command if you need it)
2) Stop the containers (required before deleting)
3) Delete containers
Here’s the script.
#!/usr/bin/env bash
docker update --restart no $(docker container ls -q -f "name=clamd")
docker update --restart no $(docker container ls -q -f "name=solr")
docker container stop $(docker container ls -q -f "name=clamd")
docker ps -a | grep "clamd" | awk '{print $1}' | xargs docker rm
docker container stop $(docker container ls -q -f "name=solr")
docker ps -a | grep "solr" | awk '{print $1}' | xargs docker rm
To return everything back to normal, simply just run:
docker-compose up -d