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.

backtest-kit-redis-mongo-docker ships three separate Docker Compose files: one for MongoDB, one for Redis, and one for the main backtest container. Keeping the infrastructure containers in their own files means you can start and stop the database layer independently from the application, making it easy to preserve data between backtest runs or share a single MongoDB/Redis instance across multiple projects.

MongoDB Container

The MongoDB service uses the official MongoDB Community Server image and persists all data to a local directory on the host so that candle history and trade records survive container restarts.
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 — MongoDB 8.0.4 on UBI 8. Pin the tag to guarantee reproducible infrastructure across machines.

Port

Host port 27017 maps to container port 27017. Ensure this port is not already occupied before starting.

Volume

./mongo_data:/data/db — all collections and indexes are stored in docker/mongodb/mongo_data/ on the host. Delete this directory to reset the database.

Restart policy

always — MongoDB restarts automatically after host reboots or unexpected exits.

Start MongoDB

docker-compose -f docker/mongodb/docker-compose.yaml up -d

Stop MongoDB

docker-compose -f docker/mongodb/docker-compose.yaml down
Running docker-compose down -v will delete the named volumes. For the MongoDB service the data is stored in a bind-mount (./mongo_data) rather than a named volume, so down -v is safe — but manually deleting docker/mongodb/mongo_data/ will permanently erase all stored candle and trade data.

Redis Container

The Redis service provides the O(1) ID cache layer. Password authentication is enforced via --requirepass so that the same credential set can be used in both local and Docker environments.
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 — Redis 7.4.1 with RDB persistence enabled by default.

Port

Host port 6379 maps to container port 6379. The application connects using CC_REDIS_PORT=6379.

Password

mysecurepassword is set via --requirepass. Must match CC_REDIS_PASSWORD in your .env file.

Volume

./redis_data:/data — RDB snapshots are written here. Delete to start with a clean cache.

Start Redis

docker-compose -f docker/redis/docker-compose.yaml up -d

Stop Redis

docker-compose -f docker/redis/docker-compose.yaml down

Changing the Redis Password

1

Update the Redis Compose file

Edit docker/redis/docker-compose.yaml and replace both occurrences of mysecurepassword — one in the environment block and one in the command array:
environment:
  - REDIS_PASSWORD=yournewpassword
command: ["redis-server", "--requirepass", "yournewpassword"]
2

Update .env

Set the matching value in your .env file so the Node.js process authenticates with the same credential:
CC_REDIS_PASSWORD=yournewpassword
3

Restart the Redis container

Bring the container down and back up to apply the new password:
docker-compose -f docker/redis/docker-compose.yaml down
docker-compose -f docker/redis/docker-compose.yaml up -d

Main Backtest Container

The primary application container runs the compiled backtest-kit strategy bundle. It connects back to MongoDB and Redis on the host using the host.docker.internal bridge hostname.
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

Image

tripolskypetr/backtest-kit (linux/amd64). The platform key ensures consistent behaviour on Apple Silicon and other ARM hosts.

Port

60050:60050 — the web UI and health-check API are exposed on this port.

Volume

./:/workspace — the entire project directory is mounted at /workspace inside the container, making your compiled strategy bundle immediately available without rebuilding the image.

Restart policy

unless-stopped — the container restarts automatically after unexpected exits but stays stopped if you run docker-compose down manually.

Start the Main Container

npm run start:docker
This script runs npm run build first, then starts the container with MODE=backtest ENTRY=1 UI=1 STRATEGY_FILE=./build/index.cjs.

Stop the Main Container

npm run stop:docker

Container-to-Host Networking with host.docker.internal

By default, localhost inside a Docker container refers to the container’s own loopback interface, not the host machine. The extra_hosts directive in the backtest container Compose file injects a special DNS entry:
extra_hosts:
  - "host.docker.internal:host-gateway"
This maps the hostname host.docker.internal to the host machine’s gateway IP, allowing the container to reach services bound to the host’s network. This is why .env.example uses host.docker.internal rather than localhost:
CC_REDIS_HOST=host.docker.internal
CC_MONGO_CONNECTION_STRING=mongodb://host.docker.internal:27017/backtest-kit?wtimeoutMS=15000
host.docker.internal is natively available on Docker Desktop for Mac and Windows. The host-gateway mapping in extra_hosts provides the same hostname on Linux hosts where it is not injected automatically.

Health Check

The backtest container includes a Docker health check that polls the application’s REST endpoint once the UI is running:
ParameterValue
EndpointGET http://localhost:60050/api/v1/health/health_check
Interval30 seconds
Timeout10 seconds
Retries3
Docker marks the container as unhealthy after 3 consecutive failures. You can inspect the health status with:
docker inspect --format='{{.State.Health.Status}}' backtest-kit-redis-mongo-docker
If the container stays in starting status, the UI may not be enabled. Make sure UI=1 is set in your .env or exported in your shell before running start:docker.

Full Startup Sequence

1

Copy and configure .env

cp .env.example .env
# Edit .env to set your passwords and connection strings
2

Start MongoDB

docker-compose -f docker/mongodb/docker-compose.yaml up -d
3

Start Redis

docker-compose -f docker/redis/docker-compose.yaml up -d
4

Build and start the backtest container

npm run start:docker
5

Verify health

docker inspect --format='{{.State.Health.Status}}' backtest-kit-redis-mongo-docker
# Expected output: healthy

Build docs developers (and LLMs) love