Scheduler
In this guide, we’ll demonstrate how to automate daily tasks using Docker, featuring an example with cryptocurrency trading using the CCXT library. This setup allows you to run a daily cron job without the hassle of managing your environment manually.
Your project can following structure:
/project-root
├── ccxt
│ ├── Dockerfile
│ ├── daily.sh
│ ├── setting.sh
│ ├── entrypoint.sh
│ └── src
│ └── *.py (your Python scripts)
└── docker-compose.yml
- Dockerfile - Defines the Docker image.
- Docker Compose - Orchestrates the Docker container.
- daily.sh - The script that executes your trading strategy daily.
- setting.sh - Contains cron settings for scheduling the task.
- entrypoint.sh - Serves as the entry point for the Docker container.
Dockerfile
The Dockerfile is responsible for setting up the environment where your scripts will run. Here’s how you structure it:
Loading content…
docker compose
The docker-compose.yml file simplifies the process of running multiple containers and helps in managing the volume mounts for your source code, such mount - ./ccxt/src:/app/src/
.
Here’s an example of how it can be structured:
Loading content…
daily.sh
The daily.sh script contains the logic for the daily task. For this demo, it serves as a placeholder for your trading operations. Customize it according to your specific needs.
Loading content…
setting.sh
This script is designed for dynamic configuration of your cron jobs without a full rebuild your Docker image whenever you want to modify the scheduling or logging.
Here’s the cron job format:
58 23 * * * /app/daily.sh >> /app/src/workspace/cron.log 2>&1"
The setting.sh script sets up a cron job. For example, to run daily.sh every day at 11:58 PM, logging the output for monitoring.
Loading content…
entrypoint.sh
The entrypoint.sh script acts as the entry point for your Docker container, executing setting.sh to initiate the scheduling of your daily tasks.
Loading content…