Do you remember my article on how to Clean Docker manually with Portainer? Today I want to show you how to clean Docker automatically, with just one click, whenever you need it. Here on mariushosting you can find a varied list of Docker images to install on your Synology NAS. However, if you ever decide to uninstall them for whatever reason, remember that it is a good practice to uninstall them properly so that, in the future, you do not experience any problems if you want to install them back from scratch. Note: With the code below you are going to automatically remove all stopped containers, unused volumes and container images from your Docker that you are no longer using.
Activate Email Notifications. If you have already activated email notifications on your Synology NAS, skip this STEP.
First of all, always remember to stop all the containers you no longer need. If you don’t stop them first, you can’t delete them.
Download the dockerprune.sh file from the blue link below, then upload it in your main Docker folder. Follow the instructions in the image below.
Go to Control Panel / Task Scheduler / Create / Scheduled Task / User-defined script. Follow the instructions in the image below.
Once you click on User-defined script, a new window will open. Follow the instructions below:
- General: In the Task field type in “Docker Cleaner“. Uncheck the “Enabled” option. Select root User.
- Schedule: Select Run on the following date then select “Do not repeat“.
- Task Settings: Check “Send run details by email“, add your email then copy paste the code below in the Run command area. After that, click OK.
After you click OK on STEP 6 a new warning pop up window will open. Click OK.
After you click OK on STEP 7, select your “Docker Cleaner” Task then click the “Run” tab. You will be asked to run Docker Cleaner – click Yes. Follow the instructions in the image below.
Note: With the task above you are going to automatically remove all stopped containers, unused volumes and container images from your Docker that you are no longer using.
Go back to STEP 1 or you will deal with karma 🙂
Check your Email. Your docker is now clean! One of the benefits you will also experience is less disk space usage on your Synology NAS!
Remove all folders in File Station that you no longer use, or have used in the past to run specific Docker images. Just delete them and recreate from scratch if you need a specific image to be reinstalled again.
Note: You can run the Docker Cleaner task at STEP 8 from time to time when you need to clean your Docker, or set a schedule to run it at a time of your choice (STEP 6 point 2). This will depend on your needs.
Note: One of the main advantages of cleaning Docker is that it will free up disk space on your NAS.
Note: Prune unused Docker objects documentation.
This post was updated on Sunday / August 21st, 2022 at 2:47 AM