Welcome back, builders! In my previous post, we created a Python Telegram bot to track $TON prices. But there is a catch: if you run the script on your PC, the bot dies the moment your computer goes to sleep.
In the crypto market, which never sleeps, downtime means missed opportunities. Today, we are going to fix that. I will show you how to containerize your Python bot using Docker. This allows you to deploy it on any cheap Cloud VPS and keep it running 24/7 flawlessly!
🛠️ What You Need:
* The Python script from our previous guide (let's save it as `bot.py`).
* Docker installed on your machine.
Step 1: Create a requirements.txt file
Docker needs to know which Python libraries your bot uses. Create a simple text file named `requirements.txt` in the same folder as your script and add this single line:
requests
Step 2: Write the Dockerfile
The Dockerfile is the magic recipe. It tells Docker how to build the environment for your bot. Create a file named exactly `Dockerfile` (no extension) and paste this inside:
FROM python:3.9-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY bot.py .
CMD ["python", "bot.py"]
Step 3: Build and Run!
Now, open your terminal (or command prompt), navigate to the folder containing your files, and run these two commands:
1. Build the image:
docker build -t my-crypto-bot .
2. Run the container in the background (Detached mode):
docker run -d --name running-bot my-crypto-bot
🚀 Why This is a Game-Changer for Traders:
By using Docker, your bot is now living in its own isolated environment. It won't crash due to weird updates on your computer. You can take this exact Docker container and run it on a $5/month cloud server (like AWS, DigitalOcean, or Hetzner).
Now you can sleep peacefully while your automated setup watches the market for you!
Did you manage to get your bot running? Drop a comment below if you need any troubleshooting help! 👇
If you appreciate these technical trading guides, consider leaving a tip or a like to support the series! 💻📈
#Write2Earn # #Docker # #Python #TradingBots #TON