Sign inSign up

hudsonventura/mt5

By hudsonventura

•Updated 8 months ago

Run MT5 in a Docker container

Image
Integration & delivery
Developer tools
1

4.0K

hudsonventura/mt5 repository overview

⁠MT5 Docker

Run MetaTrader 5 (MT5) in a Docker container.

Docker Pulls

This project runs the MT5 application inside a Docker container using Wine as a compatibility layer. The container typically consumes around 500MB of RAM (depending of broker). It's possible to run multiple containers simultaneously, each one with a separate MT5 account connected to differents brokers.
An watchdog ensures that if MT5 crashes, the container exits as well, allowing Docker to automatically restart it and maintain uptime.

Main GIF

⁠Getting Stated

Create a file docker-compose.yml downloading the file from GitHub:

wget https://raw.githubusercontent.com/hudsonventura/MT5_Docker/refs/heads/main/src/docker-compose.yml

Or copy and paste the content below:

services:

  mt5:
    image: hudsonventura/mt5:2.2

    ports:
      - "5901:5901" #VNC
      - "6901:6901" #noVNO (via browser: http://localhost:6901/vnc.html or http://localhost:6901/vnc.html?password=my_vnc_password)

    environment:
      - VNC_PW=my_vnc_password      #VNC password. Change it as you like
      - SCREEN_RESOLUTION=1024x768  #You can change as you want. Default is 1024x768

    volumes:
      - ./.data/MQL5/:/home/headless/.wine/drive_c/Program Files/MetaTrader 5/MQL5/:ro  # MQL5 folder (EAs, indicators, scripts, etc.)
      - ./mt5.ini:/home/headless/.wine/drive_c/Program Files/MetaTrader 5/mt5.ini:ro    # Use a .ini file to connect with your broker automatically, see section `After Install`
      #- ./.data/MQL5/servers.dat:/home/headless/.wine/drive_c/Program Files/MetaTrader 5/Config/servers.dat 
      # Uncomment this if you have trouble with login in your broker. See section `After Install` to get more information
       
    # Optional parameters:
    restart: always            # Automatically restarts the container if it stops
    mem_limit: 1024m           # Best practice. The container typically uses around 600MB

So:

docker compose up

⁠Accessing the container

⁠You can access the container via noVNC via browser

Go to this URL and type password manually:

http://localhost:6901/vnc.html

Or try this link to skip typing the password:

http://localhost:6901/vnc.html?password=my_vnc_password
⁠You can access the container via common VNC client app

Open your favorite VNC client app and use this address localhost:5901 and type your password set in VNC_PW environment variable.

On first run, you will see the MT5 installer. Wait a moment.
It will configure the Wine for the first run, download and install the lastest version of MT5. It usually takes around 2 minutes.
The other executions will be faster.
MT5Installer1.png MT5Installer2.png

After, you will see the MT5 running.
MT5Running.png

That's it!




⁠After install

The MT5 has a strange limitation: you cannot connect to an account unless you have searched for the server first. If you are using the DockerHub image, I have already searched for many servers. It is store in servers.dat file. This fiel is downloaded from the internet, and I try to keep it updated.
However, you can use a broken not listed in that file. So, you may need to access MT5 via VNC, check if your server is listed, and if not, search for it manually.
In this case will have to the volumes on docker-compose.yml to persist your servers.dat file.

SearchBroker1

SearchBroker2

⁠.ini file

Maybe you want to use .ini file to connect with your broker automatically.
So, see and example on srv/mt5.ini. On the first three lines, you can set your login, pass and server string.

[Common]
Login=123456
Password=YourStr0ngP@ss
Server=Test-MT5-Demo

See on srv/mt5.ini another things you can use. Whole docs in https://www.metatrader5.com/en/terminal/help/start_advanced/start⁠

⁠Compile EAs (Expert Advisors)

You can compile your MQL5 Expert Advisors without opening MetaTrader 5 manually. This is useful for CI/CD pipelines or quick builds.

Create a file docker-compose-mt5-compiler.yml downloading the file from GitHub:

wget https://raw.githubusercontent.com/hudsonventura/MT5_Docker/refs/heads/main/src/docker-compose-mt5-compiler.yml

Or copy and paste the content below:

services:

  mt5-compiler:
    image: hudsonventura/mt5:2.2
    container_name: mt5-compiler

    volumes:
      - ./mql5/Experts/:/home/headless/.wine/drive_c/MQL5/Experts/      #Expose the dir with your EAs files to compile it
      - ./mql5/Include/:/home/headless/.wine/drive_c/MQL5/Include/:ro   #Expose the dir with your Include files be used to compile the EAs
    command: /build.sh
    restart: no                # does not start again

Put your .mq5 files in the mql5/Experts/ folder and your include files in mql5/Include/. The folder structure should look like this:

.
├── docker-compose-mt5-compiler.yml
└── mql5/
    ├── Experts/
    │   └── MyExpert.mq5
    └── Include/
        └── MyLibrary.mqh

Then run:

docker compose -f docker-compose-mt5-compiler.yml up

The container will automatically download and install MT5 (on the first run), compile all .mq5 files in the Experts/ folder, and exit. The compiled .ex5 files will be available in the same mql5/Experts/ folder.

Example output:

  ╔══════════════════════════════════════════════╗
  ║   MT5 Docker - MQL5 Experts Compile          ║
  ╚══════════════════════════════════════════════╝

 [1/8] ✔  Wine OK (wine-11.2 (Staging))
 [2/8] ✔  VNC server started (port 5901)
 [3/8] ✔  Desktop environment started
 [4/8] ✔  noVNC started (port 6901)
 [5/8] ✔  Wine environment initialized
 [6/8] ✔  MT5 installer downloaded
 [7/8] ✔  MetaTrader 5 installed
 [7/8] ✔  MetaTrader 5 processes stopped
 [8/8] ✔  MQL5 Experts compiled successfully

  ╔══════════════════════════════════════════════╗
  ║         ✔  Build Complete!                    ║
  ╚══════════════════════════════════════════════╝

⁠Technology Stack

This project leverages a combination of technologies to run MT5 in a containerized environment with remote access capabilities. See the apps layers:

  • OS: Ubuntu 24.04.3 LTS - Base Linux distribution providing the foundation for the container
  • GUI:Openbox 3.6.1 - Lightweight window manager providing the desktop environment inside the container
  • Access:TigerVNC - VNC server for remote desktop access (port 5901)
  • Access:noVNC 1.4.0 - Browser-based VNC client enabling access via web browser (port 6901)
  • Compatibility Layer:Wine 10.0 - Windows compatibility layer that allows running Windows applications (MT5) on Linux
  • App:MetaTrader 5 - Trading platform with auto-update capability

⁠Build

If you are building you own version, follow the steps below. If you using the version from DockerHub, skip this section.

Build with docker compose build. Wait a while.
I will install Openbox, VNC, noVNC and Wine from the Ubuntu base image.

⁠Release Notes

⁠2.0
  • Change from accetto build to manually created ubuntu + Openbox + nVNC.
  • From arround 600MB to 500MB of RAM consumption.
  • Fixed bug where MT5 was not responding a mouse click after some seconds working.
⁠2.1
  • New console message styles.
  • Image optimization: the Docker image no longer includes MT5. It will be downloaded on the first run and the latest version will be installed automatically.
  • Reduced Docker image size.
  • The servers.dat file (which contains the server URLs) will be downloaded from GitHub on the first run and kept up to date.
⁠2.2
  • Add MQL5 expert advisor compilation functionality and docker-compose-mt5-compiler.yml file to build the container with the MQL5 expert advisor compilation functionality.

Tag summary

Content type

Image

Digest

sha256:5caf396f4…

Size

3.2 GB

Last updated

about 1 year ago

docker pull hudsonventura/mt5