-
Notifications
You must be signed in to change notification settings - Fork 0
feat: cron job for pruning docker images #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
VinneyJ
wants to merge
6
commits into
main
Choose a base branch
from
docker-cronjob
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f3dbd5c
feat: cron job for pruning docker images
VinneyJ 8dd1575
fix: add new line, remove extra implemented steps in readme
VinneyJ 82b7f4a
fix: prune everything, detailed logging, improve readme
VinneyJ ce22184
fix: typo
VinneyJ 280aee7
fix: typo
VinneyJ aeff5bd
fix: naming, remove redundancy, date to ISO 8061 format.
VinneyJ File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# Docker Image Pruning Cron Job for Dev server | ||
|
||
This README provides instructions for setting up a cron job to regularly prune old Docker images on a Dev server. Pruning Docker images helps to manage disk space effectively by removing unused images. | ||
|
||
## Prerequisites | ||
|
||
- SSH access to the Dev server. | ||
|
||
## Steps to Set Up the Cron Job | ||
|
||
### 1. Access the Dev Server | ||
|
||
SSH into your Dev server: | ||
|
||
```sh | ||
ssh [email protected] | ||
``` | ||
|
||
|
||
### 2. Set Up the Cron Job | ||
|
||
Edit the cron table to schedule the pruning job every 4 hours. | ||
|
||
Open the crontab for editing: | ||
|
||
```sh | ||
crontab -e | ||
``` | ||
|
||
Add the following line to schedule the job: | ||
|
||
``` | ||
0 */4 * * * /home/azureuser/prune_docker_images.sh | ||
``` | ||
|
||
### 3. Verify the Cron Job | ||
|
||
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_cron.log | ||
``` | ||
|
||
## Troubleshooting | ||
|
||
Check cron service status to ensure the cron service is running: | ||
|
||
```sh | ||
systemctl status cron | ||
``` | ||
|
||
#### Check Syslog for Errors | ||
|
||
If the cron job doesn’t seem to run, check the syslog for cron errors: | ||
|
||
```sh | ||
grep CRON /var/log/syslog | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/bin/bash | ||
|
||
set -o errexit | ||
set -o nounset | ||
|
||
LOGFILE="$HOME/docker_prune_cron.log" | ||
|
||
current_date=$(date -Iseconds) | ||
|
||
{ | ||
echo "Starting Docker system prune at $current_date" | ||
sudo docker system prune --volumes --force | ||
echo "Completed at $(date -Iseconds)" | ||
} >> "$LOGFILE" 2>&1 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Normally you don't want scripts laying around in a home folder. You usually put them in say ~/.local/bin, etc.
But since we're going to develop this further to be part of Dokku plugin ecosystem, I guess we can leave it here for now.