I am currently running a mac mini hosting at anytime 2 to 6 docker containers built off the same agent. The container function as build agents but every now and then builds fail and do not clean up correctly. This leads to files being left over that take up space.
I want to setup and cron job, that runs nightly, a docker exec command against every container and deletes my build directory.
i've tried the simple:
docker exec -it `docker ps -q` ls /root/build-dir
but this fails with:
OCI runtime exec failed: exec failed: container_linux.go:344: starting container process caused "exec: \"ee89958ce4bc\": executable file not found in $PATH": unknown
However this works:
docker exec -it ee89958ce4bc ls /root/build-dir
Is there a way to use docker exec against multiple container without writing a complicated script that will loop through container ID's from docker ps?
NOTE: I do not want to change the docker container and add the cron job there. I want this to run on the host machine
you can use for loop
:
for con in `docker ps -q` ; do echo "$con" && docker exec -it $con ls -l; done