Environment Variables Reference
Relevant source files
The following files were used as context for generating this wiki page:
The MT5-Docker project relies extensively on environment variables to manage container initialization, MetaTrader 5 (MT5) authentication, health monitoring, and automated demo account provisioning. These variables allow the system to operate in a "zero-touch" manner, automatically configuring Wine prefixes, installing dependencies, and managing the MT5 terminal lifecycle without manual intervention.
Configuration is primarily handled via a .env file or direct injection into the Docker container, with fallback values defined in the orchestration scripts and build manifests.
Sources: README.md:214-235, docker/container/metatrader/start.sh:22-55
Core Authentication and Account Settings
These variables are used to authenticate the MetaTrader 5 terminal. If MT5_LOGIN is provided, the system attempts to configure the terminal using these credentials. If omitted and MT5_AUTO_CREATE_DEMO is enabled, the system initiates a GUI automation script to provision a new account.
| Variable | Default | Description |
|---|---|---|
MT5_LOGIN | - | MetaTrader 5 account number for auto-login. |
MT5_PASSWORD | - | Password associated with the MT5 account. |
MT5_SERVER | MetaQuotes-Demo | The broker server name to connect to. |
MT5_AUTO_CREATE_DEMO | 0 | If 1, enables headless "Open an Account" wizard when MT5_LOGIN is unset. |
Sources: README.md:214-220, docker/compose.yaml:52-54, docker/container/metatrader/start.sh:58-61
Automated Demo Provisioning Flow
When MT5_AUTO_CREATE_DEMO is active, the container executes open_demo_account.py. This script uses various MT5_DEMO_* variables to fill out the registration form via xdotool.
The diagram shows the logic flow for determining how MetaTrader 5 credentials are provisioned during container startup.
Sources: docker/container/metatrader/open_demo_account.py:35-50, docker/container/metatrader/start.sh:78-83
Feature Control and Health Monitoring
These variables manage the operational behavior of the container, including recovery logic and optional software installations.
| Variable | Default | Description |
|---|---|---|
AUTO_RECOVERY_ENABLED | 1 | Enables background health monitor to restart MT5/gRPC on failure. |
HEALTH_CHECK_INTERVAL | 30 | Frequency in seconds for health status verification. |
ENABLE_WIN_DOTNET | 1 | Triggers installation of .NET Framework 4.8 via Wine Mono for .NET EAs. |
MT5_DEBUG | 0 | Enables verbose debug logging in the gRPC bridge. |
MT5_UPDATE | 1 | If 1, updates the MetaTrader5 pip package on startup. |
Sources: README.md:221-226, docker/compose.yaml:47-50
System and Wine Environment
The container's internal architecture is defined by path and version variables. These are critical for the correct functioning of the Wine environment and the dual Python architecture (System Python 3.13 and Wine Python 3.12).
Path Configurations
| Variable | Default | Description |
|---|---|---|
WINEPREFIX | /config/.wine | Directory containing the Wine environment and MT5 installation. |
CONFIG_DIR | /config | Root directory for persistent data, settings, and logs. |
STAGING_DIR | /opt/mt5-staging | Location for pre-downloaded installers and version manifests. |
WINE_PYTHON_PATH | $WINEPREFIX/drive_c/Python/python.exe | Path to the Windows-compatible Python executable. |
Sources: docker/container/metatrader/start.sh:25-39, tests/constants.py:112-114
Dependency Versions
These variables are sourced from STAGING_DIR/.versions and define the specific versions of components used during the setup.sh process.
The diagram illustrates how start.sh exports version-specific environment variables used by setup.sh to pin dependencies.
Sources: docker/container/metatrader/start.sh:45-55, docker/container/metatrader/setup.sh:166-175
Network and Integration Settings
Environment variables also control the exposure of ports for remote access and communication with the mt5linux library.
| Variable | Default | Description |
|---|---|---|
MT5_VNC_PORT | 3000 | Port for the KasmVNC web interface. |
MT5_GRPC_PORT | 8001 | Port for the gRPC bridge server (remote control). |
MT5_HEALTH_PORT | 8002 | Port for internal health check endpoints. |
DISPLAY | :0 | The X11 display used for GUI automation. |
Sources: docker/compose.yaml:26-28, tests/constants.py:126-128, docker/container/metatrader/open_demo_account.py:28
Summary
Environment variables in the MT5-Docker project serve as the primary configuration mechanism for a complex multi-layered system involving Linux, Wine, and MetaTrader 5. By manipulating these variables, administrators can toggle between using existing accounts or automated demo accounts, control the update frequency of components, and manage the underlying resource limits and network accessibility of the trading environment.
Sources: README.md:214-235, docker/compose.yaml:35-58