In this episode, I build upon the last topic around FreqTrade’s integrated Dashboard, and show you how to quickly scale out your army or FreqTrade bots, by storing the container variables as Docker environment variables, so you only have one place you need to make changes, as you copy and deploy your bots rapidly. Check out the video, and when you’re ready, below is the sample code you came here for!
Also, if you’re looking for a great machine to run your fleet of FreqTrade bots on, I highly recommend this small form-factor Intel NUC – this is an amazing price on a rock-solid piece of hardware, in a compact, silent, power-efficient format! Please note this is an affiliate link and I may receive a commission from your purchase. Clicking this link and completing your regular Amazon purchases is an easy no-cost way to support the channel!
Here’s your sample code for your docker-compose.yml file:
version: '3.3'
networks:
proxy:
external: true
services:
freqtrade:
image: freqtradeorg/freqtrade:develop
volumes:
- ./user_data:/freqtrade/user_data
- /etc/timezone:/etc/timezone:ro
command: >
trade
--logfile /freqtrade/user_data/logs/freqtrade.log
--config /freqtrade/user_data/config.json
--strategy ${STRATEGY}
--db-url sqlite:///user_data/${DATABASE_FILE}
networks:
- proxy
deploy:
mode: replicated
replicas: 1
placement:
constraints:
- node.role == manager
restart_policy:
condition: on-failure
delay: 5s
labels:
- 'traefik.http.routers.${BOTNAME}.tls=true'
- 'traefik.http.routers.${BOTNAME}.rule=Host(`${BOTNAME}.bots.yourdomain.com`)'
- 'traefik.http.services.${BOTNAME}.loadbalancer.server.port=8080'
In the above sample code, it’s important that you are using a wildcard subdomain in the bots.yourdomain.com placeholder. If you are not familiar, this means you want everything (*) under that namespace to resolve to the IP of your docker host. If you need a refresher on this, check out my Traefik proxy video, I cover this in-depth!
Next, you need the .env file that contains the variables referenced in the sample docker-compose.yml, so, here you go!
BOTNAME=bot001
STRATEGY=BinHV45
DATABASE_FILE=trades.sqlite
The above file should be saved as a hidden “dot file” in the same path with your docker-compose.yml file, as .env
The BOTNAME variable dictates what the fully-qualified name of the deployed bot will be, ie: https://bot001.bots.yourdomain.com
The STRATEGY variable needs to be the exact (case-sensitive) name of your strategy file, which is stored in user_data/strategies folder
Also remember when you’re copying your base FreqTrade folder (this was bot001 in the video, for example), that you want to go in and remove the existing trades.sqlite database, and clear the logs by removing the logs/freqtrade.log file if it exists, after copying, and before deploying
Lastly, you’re probably looking for that command that lets you use .env variables with a docker stack deploy deployed container! Here you go:
docker stack deploy -c <(docker-compose config) stackName
This looks similar to the standard deploy command, however we can see that in place of where we normally reference the docker-compose.yml file, we’re telling it to evaluate that configuration with docker-compose instead! When this runs, it builds the config, evaluating the variables, and then passes that all back to docker stack deploy to complete the deployment.
I hope this is helpful to you! Please give me a thumbs up on the video if you found it useful, subscribe if you’re not already, and leave me a comment if you have questions or thoughts! Thank you!
Any chance you could post the docker-compose.yml of traefik and freqtrade side by side. I copied them seperately from both your videos, but I have a feeling that you might have changed the labels in the docker-compose.yml of traefik when making the freqtrade video’s (changed form botname.dmz.yourdomain.com to botname.bots.yourdomain.com for example).
Hello,
I try to do the same thing like you but I still don’t understand how it’s working.
I saw your video for docker and traefik and I guess you used different machine to create a node manager and worker. The thing is, Im confused about stack and service. because In this video you have all you services attach to a swarm but it look like all your bot its on the same machine…?? how you do that ? I have only a server (on linode) and a domain attach to this serveur and I would like to obtain the same result : create many bot with different strategies and access to them into my domain.
Do you have each bot on different server ? How do you manage to have all your bot on a stack ?
Im sorry if it’s not really clear Im totally beginner with docker I still try to understand… and English is not my native language so its kind of diffuclt to explain it
Thanks !
Hi Dan, thank you for your help..
Hopefully I have managed how to install traefik, portainer, letsencrypt and freqtrade as a docker stack, one problem is that the freqtrade-UI does not start.
My quesion is why is using stacks is more beneficial ?
Cheers mate!