Dzhuneyt
Posted on March 22, 2024
I have a Synology NAS at home that I use for various purposes. One of the things I do with it is run a Docker Compose
project that contains a few services.
I have a few services that I want to run on a schedule. For example, a backup service that
runs every night or a media optimizer container that takes my movie library and converts it to playback formats, that
are more suitable for older smart TVs.
In this post, I will show you how to run a Docker Compose project on a schedule using the Synology Container Manager and
the Synology Task Scheduler.
Prerequisites
You will need to use Google Chrome or another browser that allows you to inspect Network requests.
Getting the Docker Compose project ID
Inspecting the Network requests is the only way to retrieve the unique ID that Synology uses to identify the Docker
Compose project.
We will need this ID later, so let's first explore how to find it.
Assuming you already created a "Project" inside "Container Manager" (a project is a fancy name that DSM uses for Docker
Compose stacks). Open the "Container Manager" and navigate to the project you want to run on a schedule. If it was
already running, stop it.
Before starting it again, open the Network inspector of your browser. If you are using Chrome on a Mac, you can do this
via Cmd + Option + I
and then click on the "Network" tab. Other browsers obviously have similar developer tools but
you need to Google a bit how to find it, if you haven't used it before.
Hit the "Clear network log" button at the left of this floating window if you want to reduce clutter. Finally, start the
project by clicking the "Start" button in the Container Manager and observe the Network requests. You should find one
that looks like this:
SYNO.Docker.Project
Open it, and inside the "Payload" tab, you will find a JSON object that contains the ID of the project. It should be
something long and random looking, for example:
9fb91ca5-d817-42f8-8ddc-2acdf4d94494
Take note of this ID, because you will need it in the next step.
Scheduling a CRON job via Synology Task Scheduler
Open the Control Panel of your Synology NAS and navigate to the "Task Scheduler" app. Click on "Create" and then "
Scheduled Task" -> "User-defined script".
Name your task based on your preferences, e.g. "Run Backup service on schedule".
In the "User" dropdown, select "root"; otherwise Synology will not have the necessary permissions to run the Docker
Compose project.
In the "Schedule" tab pick the schedule that suits your needs.
In the "Task Settings" tab, inside the "User-defined script" text box, paste the following script:
synowebapi --exec api=SYNO.Docker.Project method="start_stream" version=1 id="9fb91ca5-d817-42f8-8ddc-2acdf4d94494"
Note: Replace the id
value with the ID you found in the previous step.
That's it! Synology will not start the Project based on the schedule that you provided.
Posted on March 22, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
March 22, 2024