Created
          November 22, 2018 12:25 
        
      - 
      
 - 
        
Save sirkonst/413475ee055a588c58661363c461122e to your computer and use it in GitHub Desktop.  
    Remove unused docker resources with systemd (service and timer)
  
        
  
    
      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
    
  
  
    
  | [Unit] | |
| Description=Remove unused docker resources | |
| Documentation=https://docs.docker.com/v17.09/engine/admin/pruning/ | |
| After=docker.service | |
| [Service] | |
| Type=oneshot | |
| ExecStart=/usr/bin/docker system prune -f --filter "until=744h" | |
| ExecStart=/usr/bin/docker volume prune -f | |
| TimeoutSec=10m | |
| [Install] | |
| WantedBy=multi-user.target | 
  
    
      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
    
  
  
    
  | [Unit] | |
| Description=Run docker-prune daily | |
| [Timer] | |
| OnCalendar=daily | |
| Persistent=true | |
| [Install] | |
| WantedBy=timers.target | 
Run manually: systemctl start docker-prune
Check result: systemctl status docker-prune or journalctl -u docker-prune
Should you not want to start docker-prune.timer right after configuration but rather at the configured time, run systemctl restart timers.target instead. (https://unix.stackexchange.com/questions/563896/systemd-timer-will-not-fire/563897#563897)
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
/etc/systemd/system/systemctl daemon-reloadsystemctl enable docker-prune.timersystemctl start docker-prune.timer