Skip to content

Commit

Permalink
fix: prune everything, detailed logging, improve readme
Browse files Browse the repository at this point in the history
  • Loading branch information
VinneyJ committed Jun 27, 2024
1 parent 8dd1575 commit 82b7f4a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
2 changes: 0 additions & 2 deletions docker-cronjob/prune_docker_images.sh

This file was deleted.

8 changes: 7 additions & 1 deletion docker-cronjob/README.md → docker-prune-cron/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ crontab -e
Add the following line to schedule the job:

```
0 */4 * * * /home/azureuser/prune_docker_images.sh > /dev/null 2>&1
0 */4 * * * /home/azureuser/prune_docker_images.sh
```

### 3. Verify the Cron Job
Expand All @@ -40,6 +40,12 @@ List the current cron jobs to ensure your job is added:
```sh
crontab -l
```
You can also check the logged output:

```sh

cat docker_prune.log
```

## Troubleshooting

Expand Down
16 changes: 16 additions & 0 deletions docker-prune-cron/prune_docker_images.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

set -o errexit

LOGFILE="$HOME/docker_prune.log"

{
echo "Starting Docker system prune at $(date)"
sudo /usr/bin/docker system prune -f
echo "Pruned Docker objects successfully"

echo "Starting Docker volume prune at $(date)"
sudo /usr/bin/docker system prune --volumes -f
echo "Pruned Docker volumes successfully"
echo "Completed at $(date)"
} >> "$LOGFILE" 2>&1

0 comments on commit 82b7f4a

Please sign in to comment.