Run MetaTrader5 on any OS via Docker.
5.2K
A containerized solution for running MetaTrader5 trading platform with web-based VNC access and Python API support.
The official image is available on Docker Hub:
Repository: jsfrnc/mt5-docker-api
docker pull jsfrnc/mt5-docker-api:latest
This Docker image allows you to run MetaTrader5 on any system that supports Docker, providing:
Pull and run the latest image from Docker Hub:
# Pull the latest image
docker pull jsfrnc/mt5-docker-api:latest
# Run the container
docker run -d \
--name mt5-docker \
-p 3000:3000 \
-p 8000:8000 \
-p 8001:8001 \
-e VNC_PASSWORD=yourpassword \
-v mt5_data:/root/.wine/drive_c/Program\ Files/MetaTrader\ 5 \
jsfrnc/mt5-docker-api:latest
Available tags:
jsfrnc/mt5-docker-api:latest - Latest stable versionjsfrnc/mt5-docker-api:v1.0.2 - Specific versionmkdir mt5-docker && cd mt5-docker
wget https://raw.githubusercontent.com/jefrnc/mt5-docker-api/main/docker-compose.yml
wget https://raw.githubusercontent.com/jefrnc/mt5-docker-api/main/.env.example
cp .env.example .env
nano .env # Edit with your settings
docker compose up -d
The image jsfrnc/mt5-docker-api:latest will be automatically pulled from Docker Hub.
http://localhost:3000.envhttp://localhost:8000/docsdocker run -d \
-p 3000:3000 \
-p 8000:8000 \
-p 8001:8001 \
-v mt5_data:/root/.wine/drive_c/Program\ Files/MetaTrader\ 5 \
-e VNC_PASSWORD=yourpassword \
-e MT5_LOGIN=your_login \
-e MT5_PASSWORD=your_password \
-e MT5_SERVER=your_server \
jsfrnc/mt5-docker-api:latest
| Variable | Required | Default | Description |
|---|---|---|---|
VNC_PASSWORD | Yes | - | VNC connection password |
MT5_LOGIN | No | - | MetaTrader5 account login |
MT5_PASSWORD | No | - | MetaTrader5 account password |
MT5_SERVER | No | - | MetaTrader5 broker server |
API_KEY | No | - | API key for authenticating REST API requests via X-API-Key header. If not set, auth is disabled (for local dev) |
ALLOWED_ORIGINS | No | http://localhost:8080 | Comma-separated list of allowed CORS origins |
VNC_PORT | No | 3000 | Web VNC interface port |
API_PORT | No | 8000 | REST API server port |
MT5_PORT | No | 8001 | Python MT5 server port |
WINEPREFIX | No | /root/.wine | Wine prefix directory |
MT5_VERSION | No | 5.0.36 | MetaTrader5 Python library version |
WINE_VERSION | No | win10 | Wine compatibility mode |
LOG_LEVEL | No | INFO | Logging verbosity |
/root/.wine/drive_c/Program Files/MetaTrader 5: MT5 installation and data (persistent across restarts)/app/logs: Application logsThe container includes a REST API with automatic documentation:
# Get account info (include X-API-Key header if API_KEY is configured)
curl -H "X-API-Key: YOUR_KEY" http://localhost:8000/account
# Get available symbols
curl http://localhost:8000/symbols
# Get symbol details
curl http://localhost:8000/symbol/EURUSD
# Place an order
curl -X POST http://localhost:8000/order \
-H "Content-Type: application/json" \
-d '{
"symbol": "EURUSD",
"volume": 0.01,
"order_type": "BUY"
}'
# Get open positions
curl http://localhost:8000/positions
# Get historical data
curl -X POST http://localhost:8000/history/candles \
-H "Content-Type: application/json" \
-d '{
"symbol": "EURUSD",
"timeframe": "M5",
"start": "2024-01-01T00:00:00",
"end": "2024-01-02T00:00:00"
}'
// Connect to real-time tick stream
const ws = new WebSocket('ws://localhost:8000/ws/ticks/EURUSD');
ws.onmessage = (event) => {
const tick = JSON.parse(event.data);
console.log(`${tick.symbol}: Bid=${tick.bid}, Ask=${tick.ask}`);
};
You can also connect directly to MT5 without the REST API:
from mt5linux import MetaTrader5
# Connect to the container
mt5 = MetaTrader5(host='localhost', port=8001)
mt5.initialize()
# Check version
print(mt5.version())
# Your trading logic here
If you mount the MT5 volume locally, place your Expert Advisors and Scripts in:
./mt5/MQL5/
Access MetaEditor through the MT5 interface for development.
git clone https://github.com/jefrnc/mt5-docker-api
cd mt5-docker-api
docker build -t mt5-docker-api:latest .
docker logs mt5docker pshttp://localhost:3000 directlydocker exec mt5 wine --versionThis project is licensed under the MIT License. See LICENSE for details.
Free, and maintained on my own time. Sponsorship covers the market data and broker API access behind these tools, and keeps them working when brokers change their export formats.
Content type
Image
Digest
sha256:668bc90ba…
Size
1.6 GB
Last updated
about 1 month ago
docker pull jsfrnc/mt5-docker-api