Skip to content

Deploying a MetaTrader5 App

Introduction

MetaTrader5 (MT5) is a proprietary multi-asset trading platform. Deploying MT5 with a Dockerfile on Klutch.sh lets you containerize the terminal for automated strategies or API bridges while keeping secrets managed and storage persistent—all from klutch.sh/app. This guide assumes you supply your own licensed MT5 terminal binaries and broker configuration; it covers installation, repository prep, a production-ready Dockerfile, deployment steps, Nixpacks overrides, sample usage, and production tips.


Prerequisites

  • A Klutch.sh account (sign up)
  • A GitHub repository containing your MT5 terminal bundle (from your licensed distribution) and Dockerfile (GitHub is the only supported git source)
  • Broker credentials and configuration files (e.g., config/terminal.ini, server .srv files)
  • Optional: strategy or bridge code (Python/Node) that talks to MT5 via local APIs

For onboarding, see the Quick Start.


Architecture and ports

  • MT5 itself does not expose an HTTP API; it connects out to your broker. If you run a local bridge (REST/WebSocket) alongside MT5, expose it on internal port 3000 and choose HTTP traffic.
  • No external database is required for the terminal; your strategies may use one separately.
  • Persistent storage is required for terminal data, logs, and any bridge artifacts.

Repository layout

metatrader5/
├── Dockerfile # Must be at repo root for auto-detection
├── mt5-terminal/ # Your licensed MT5 terminal files (not provided here)
├── config/terminal.ini # Broker/login configuration (no secrets in Git)
├── bridge/ # Optional REST/WebSocket bridge code
└── README.md

Keep secrets and broker credentials out of Git; store them in Klutch.sh environment variables.


Installation (local) and starter commands

Validate locally before pushing to GitHub:

Terminal window
docker build -t mt5-local .
docker run -p 3000:3000 -e MT5_LOGIN=<login> -e MT5_PASSWORD=<password> mt5-local

Dockerfile for MetaTrader5 (production-ready)

Place this Dockerfile at the repo root; Klutch.sh auto-detects it (no Docker selection in the UI). This example runs MT5 under Wine and, if present, starts a local bridge on port 3000.

FROM ubuntu:22.04
ENV DEBIAN_FRONTEND=noninteractive \
MT5_HOME=/opt/mt5 \
PORT=3000
RUN dpkg --add-architecture i386 && \
apt-get update && \
apt-get install -y --no-install-recommends \
wget xvfb xauth dbus-x11 supervisor \
wine64 wine32 winbind ca-certificates \
python3 python3-pip && \
rm -rf /var/lib/apt/lists/*
WORKDIR ${MT5_HOME}
COPY mt5-terminal/ ./terminal/
COPY config/ ./config/
COPY bridge/ ./bridge/
# Optional: install bridge dependencies if you have a Python bridge
RUN if [ -f bridge/requirements.txt ]; then pip3 install --no-cache-dir -r bridge/requirements.txt; fi
# Lightweight health endpoint on 3000 if you provide bridge/app.py (FastAPI/Flask)
ENV WINEDEBUG=-all
RUN printf '#!/usr/bin/env bash\nset -e\nxvfb-run -a wine ${MT5_HOME}/terminal/terminal64.exe /portable /config:${MT5_HOME}/config/terminal.ini &\nif [ -f ${MT5_HOME}/bridge/app.py ]; then cd ${MT5_HOME}/bridge && python3 app.py --port ${PORT}; else while true; do echo "MT5 running"; sleep 60; done; fi\n' > /entrypoint.sh \
&& chmod +x /entrypoint.sh
EXPOSE 3000
CMD ["/entrypoint.sh"]

Notes:

  • You must supply the MT5 terminal files in mt5-terminal/; they are not redistributed here.
  • Adjust the bridge to your needs (Flask/FastAPI/Node). If you don’t run a bridge, keep the port for health checks or remove it.
  • Add build tools (apt-get install -y build-essential) if your bridge or strategies require native deps.

Environment variables (Klutch.sh)

Set these in Klutch.sh before deploying:

  • MT5_LOGIN=<broker-login>
  • MT5_PASSWORD=<broker-password>
  • MT5_SERVER=<broker-server> (if referenced by your config)
  • MT5_HOME=/opt/mt5
  • PORT=3000 (for an optional bridge/health endpoint)
  • Any API keys your bridge or strategies require

If you deploy without the Dockerfile and need Nixpacks overrides (bridge-only):

  • NIXPACKS_BUILD_CMD=pip install -r bridge/requirements.txt && python -m compileall bridge
  • NIXPACKS_START_CMD=python bridge/app.py --port 3000
  • NIXPACKS_PYTHON_VERSION=3.11 (adjust to your bridge runtime)

Attach persistent volumes

In Klutch.sh storage settings, add mount paths and sizes (no names required):

  • /opt/mt5/terminal — terminal data, logs, and profiles.
  • /opt/mt5/config — configuration files (non-secret defaults).
  • /opt/mt5/bridge — optional bridge artifacts (tokens, cache).

Ensure these directories are writable.


Deploy MetaTrader5 on Klutch.sh (Dockerfile workflow)

  1. Push your repository—with the Dockerfile and your licensed MT5 terminal files at the root—to GitHub.
  2. Open klutch.sh/app, create a project, and add an app.
  3. Select HTTP traffic and set the internal port to 3000 (for your bridge/health endpoint).
  4. Add the environment variables above, including broker credentials and any bridge API keys.
  5. Attach persistent volumes for /opt/mt5/terminal, /opt/mt5/config, and /opt/mt5/bridge sized for your logs and data.
  6. Deploy. Your optional bridge or health endpoint will be reachable at https://example-app.klutch.sh; MT5 will connect out to your broker using the supplied credentials.

Sample API usage (bridge example)

If your bridge exposes a simple account status endpoint on port 3000:

Terminal window
curl -X GET "https://example-app.klutch.sh/api/status" \
-H "Authorization: Bearer <token>"

Health checks and production tips

  • Add an HTTP probe to your bridge/health endpoint (e.g., /healthz).
  • Enforce HTTPS at the edge; forward internally to port 3000.
  • Keep broker credentials and API keys in Klutch.sh secrets and rotate regularly.
  • Pin base image versions and back up /opt/mt5/terminal before upgrades.
  • Monitor disk usage for logs and data; resize volumes before they fill.

MetaTrader5 on Klutch.sh combines reproducible Docker builds with managed secrets, persistent storage, and flexible HTTP/TCP routing. With the Dockerfile at the repo root, port 3000 configured for your bridge, and your licensed terminal files supplied, you can containerize MT5-driven workflows without extra YAML or workflow overhead.