Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/theonetrade/backtest-kit-redis-mongo-docker/llms.txt

Use this file to discover all available pages before exploring further.

This page describes how to deploy the full backtest-kit-redis-mongo-docker stack, from a lightweight local setup where Node.js runs on the host against dockerized infrastructure, through to a fully containerized deployment where the backtest runner, MongoDB, and Redis all run inside Docker.

Deployment Approaches

There are two distinct ways to run the stack depending on your environment and operational preferences. Local run (host Node.js + dockerized infrastructure). MongoDB and Redis run as Docker containers while the strategy bundle executes directly on the host with npm run start. This is the recommended approach during active strategy development because it gives you fast rollup rebuild cycles without rebuilding a Docker image. Full Docker deploy. All three services — MongoDB, Redis, and the backtest runner — run inside Docker. The runner container mounts your local workspace at /workspace, so you still build with rollup -c on the host but execution happens inside the container. This is the recommended approach for unattended server deployments.

Full Docker Deploy

Before starting the full stack, build the TypeScript source so the compiled bundle is available for the container to mount.
npm run build
Then bring up all services using the environment variables expected by the main docker-compose.yaml:
MODE=backtest ENTRY=1 UI=1 STRATEGY_FILE=./build/index.cjs docker-compose up -d
VariableValue used aboveMeaning
MODEbacktestInstructs the CLI entrypoint to run in backtest mode
ENTRY1Equivalent to passing --entry on the CLI; activates the main function
UI1Enables the web dashboard on port 60050
STRATEGY_FILE./build/index.cjsPath (relative to /workspace inside the container) to the compiled strategy bundle

npm Shortcuts

The package.json provides two convenience scripts that wrap the commands above. Start the full stack in backtest mode:
npm run start:docker
This is equivalent to running npm run build && cross-env MODE=backtest ENTRY=1 UI=1 STRATEGY_FILE=./build/index.cjs docker-compose up -d. Stop and remove all containers:
npm run stop:docker
This calls docker-compose down, which stops all containers defined in the main docker-compose.yaml and removes their networks. Persistent data in docker/mongodb/mongo_data and docker/redis/redis_data is preserved on the host.

Docker Compose Layout

The project uses three separate compose files to keep infrastructure concerns isolated. They can be started independently or together depending on which services you need.

docker/mongodb/docker-compose.yaml

Runs the official MongoDB Community Server.
services:
  mongodb:
    image: mongodb/mongodb-community-server:8.0.4-ubi8
    container_name: mongodb
    ports:
      - '27017:27017'
    volumes:
      - ./mongo_data:/data/db
    restart: always
  • Image: mongodb/mongodb-community-server:8.0.4-ubi8 — a production-supported build of MongoDB 8.0 on UBI 8.
  • Port: 27017 exposed on the host.
  • Volume: ./mongo_data:/data/db persists the WiredTiger data files on the host.
  • Restart policy: always — MongoDB restarts automatically on host reboot.

docker/redis/docker-compose.yaml

Runs Redis with password authentication enabled.
services:
  redis:
    image: redis:7.4.1
    container_name: redis
    ports:
      - "6379:6379"
    environment:
      - REDIS_PASSWORD=mysecurepassword
    command: ["redis-server", "--requirepass", "mysecurepassword"]
    volumes:
      - ./redis_data:/data
    restart: always
  • Image: redis:7.4.1 — the official Redis image pinned to a specific patch release.
  • Port: 6379 exposed on the host.
  • Authentication: --requirepass mysecurepassword passed directly to redis-server. Override this value and update CC_REDIS_PASSWORD in .env before any internet-facing deployment.
  • Volume: ./redis_data:/data persists the RDB snapshot between restarts.
  • Restart policy: always.
The default Redis password mysecurepassword is shown in plain text in this compose file for development convenience. In production, use a Docker secret or inject the password via a .env file that is excluded from version control.

docker-compose.yaml (main runner)

Runs the tripolskypetr/backtest-kit image with your compiled strategy bundle mounted in.
services:
  backtest:
    image: tripolskypetr/backtest-kit
    platform: linux/amd64
    extra_hosts:
      - "host.docker.internal:host-gateway"
    container_name: backtest-kit-redis-mongo-docker
    ports:
      - "60050:60050"
    restart: unless-stopped
    volumes:
      - ./:/workspace
    working_dir: /workspace
    environment:
      - MODE
      - STRATEGY_FILE
      - SYMBOL
      - STRATEGY
      - EXCHANGE
      - FRAME
      - UI
      - TELEGRAM
      - VERBOSE
      - NO_CACHE
      - NO_FLUSH
      - ENTRY
    env_file:
      - .env
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:60050/api/v1/health/health_check"]
      interval: 30s
      timeout: 10s
      retries: 3

extra_hosts and Host Network Access

The extra_hosts entry:
extra_hosts:
  - "host.docker.internal:host-gateway"
adds a /etc/hosts record inside the container that maps host.docker.internal to the host machine’s gateway IP. This is the Linux equivalent of the automatic host.docker.internal DNS entry that Docker Desktop provides on macOS and Windows. Without this entry, the container cannot resolve host.docker.internal, and the .env values for CC_REDIS_HOST and CC_MONGO_CONNECTION_STRING — which both reference host.docker.internal — will fail to connect to the infrastructure containers started from docker/mongodb/ and docker/redis/.
If you are deploying MongoDB and Redis on a separate host or using a managed cloud service, replace host.docker.internal in .env with the actual hostname or IP address of that service. The extra_hosts entry is not needed in that case.

Health Check

The main compose file configures an HTTP health check against the backtest-kit REST API:
GET http://localhost:60050/api/v1/health/health_check
Docker polls this endpoint every 30 seconds with a 10-second timeout and marks the container unhealthy after 3 consecutive failures. Use docker inspect backtest-kit-redis-mongo-docker to query the current health status.
docker inspect --format='{{.State.Health.Status}}' backtest-kit-redis-mongo-docker

Volume Mounts

MountHost pathContainer pathPurpose
Workspace.//workspaceProvides the compiled strategy bundle and .env to the runner
MongoDB datadocker/mongodb/mongo_data/data/dbPersists all collection data across container restarts
Redis datadocker/redis/redis_data/dataPersists the RDB snapshot across container restarts
The workspace mount is the critical one for the runner container. Because working_dir is set to /workspace, the STRATEGY_FILE=./build/index.cjs path resolves to the build/ directory that rollup -c produces on the host. There is no need to copy files into the image or rebuild it when the strategy code changes.

Environment Variable Reference

All variables listed in the environment block of the main docker-compose.yaml are passed through from the host shell or the .env file. None have hardcoded values in the compose file itself, which means unset variables are silently ignored by the runner rather than causing a startup error.
VariablePurpose
MODESelects the run mode: backtest, live, or paper
STRATEGY_FILEPath to the compiled strategy bundle inside the container (default: ./build/index.cjs)
ENTRYSet to 1 to activate the main entry point; without this the process exits immediately
SYMBOLOverride the default trading symbol defined in the strategy
STRATEGYOverride the strategy name used for MongoDB lookups
EXCHANGEOverride the exchange name used for MongoDB lookups
FRAMEOverride the frame name used for MongoDB lookups
UISet to 1 to enable the web dashboard on port 60050
TELEGRAMSet to 1 to enable Telegram notifications for signals and risk events
VERBOSESet to 1 to enable verbose logging to stdout
NO_CACHESet to 1 to disable Redis cache reads (all lookups go directly to MongoDB)
NO_FLUSHSet to 1 to skip the Redis cache flush performed at startup
During development it is convenient to set NO_FLUSH=1 to preserve the warm Redis cache between quick restarts. In production backtests, leave NO_FLUSH unset so each run starts with a clean cache and there is no risk of stale ID mappings from a previous run influencing the results.

Build docs developers (and LLMs) love