This repository contains a minimal Docker image + Docker Compose setup for running Telegram MTProxy with:
- Automatic refresh of official Telegram proxy secret/config
- HTTP stats endpoint
- Multi-secret support
- Multi-port support
- Fake-tls support
Official MTProxy project: https://github.com/TelegramMessenger/MTProxy
curl -O https://raw.githubusercontent.com/kr-ilya/mtproxy-installer/main/install.sh
chmod +x install.sh
./install.shYou can set these in .env (recommended) or directly in your shell.
| Variable | Default | Description | Example |
|---|---|---|---|
FAKE_TLS |
0 |
Fake TLS mode. | FAKE_TLS=1 |
FAKE_TLS_DOMAIN |
cloudflare.com |
Fake TLS domain. | FAKE_TLS_DOMAIN=cloudflare.com |
PORT |
443 |
Single public port (used if PORTS is empty). |
PORT=443 |
PORTS |
(empty) | Multiple public ports (comma-separated). Overrides PORT. |
PORTS=443,8443,9443 |
SECRET |
(empty) | Single secret (32 hex chars). If empty and /data/secret does not exist, it will be auto-generated and saved to /data/secret. |
SECRET=0123456789abcdef0123456789abcdef |
SECRETS |
(empty) | Multiple secrets (comma or space-separated). Overrides SECRET. |
SECRETS=aaa... bbb... or SECRETS=aaa...,bbb... |
TAG |
(empty) | Tag from @MTProxybot. | TAG=your_tag_from_bot |
WORKERS |
(auto) | Number of worker processes (auto-detected, capped to 16 in entrypoint). | WORKERS=4 |
EXTERNAL_IP |
(auto-detect) | External IP used to generate tg://proxy links. If not set, auto-detected; fallback to container IP. |
EXTERNAL_IP=203.0.113.10 |
STATS_PORT |
8888 |
HTTP stats port. | STATS_PORT=8888 |
CONFIG_UPDATE_INTERVAL |
604800 |
Telegram config update interval in seconds (getProxySecret / getProxyConfig). Set 0 to disable updates. |
CONFIG_UPDATE_INTERVAL=86400 |
These are passed as build args (configured in docker-compose.yml).
| Argument | Default | Description |
|---|---|---|
MTPROTO_REPO_URL |
https://github.com/TelegramMessenger/MTProxy |
Upstream repository URL to build MTProxy from. |
MTPROTO_COMMIT |
cafc338 |
Commit / tag to checkout before building. |
A prebuilt image is available on Docker Hub.
git clone https://github.com/kr-ilya/mtproxy-docker.git
cd mtproxy-dockercp .env.example .envEdit .env as needed (for example set PORT, SECRET or SECRETS, TAG).
sudo docker compose up -dsudo docker compose logs -fOn startup, the container prints connection links like:
tg://proxy?server=YOUR_IP&port=443&secret=dd<YOUR_SECRET>
Build locally
If you want to build the MTProxy binary yourself (for example to pin a different commit upstream sources), use:
sudo docker compose build --no-cache
sudo docker compose up -dIf you prefer Makefile helpers:
make build
make run
make logssudo docker compose pull mtproxy
sudo docker compose up -d --force-recreate- Keep your secrets private.
- Consider restricting stats access (by default the compose file maps stats to
127.0.0.1only). - If you expose stats publicly, protect it with firewall rules or reverse proxy auth.
Important note: the official MTProxy binary currently does not support process IDs (PIDs) larger than 65535.
In long-running containers or on systems where many processes are started, PIDs can grow beyond this limit. When that happens, MTProxy may crash immediately on startup with an error like:
mtproto-proxy: common/pid.c:42: init_common_PID: Assertion `!(p & 0xffff0000)' failed
You can limit the maximum PID the kernel assigns to new processes, which prevents this crash. This is not required for most users and may not be suitable in all environments. Run:
echo "kernel.pid_max = 65535" | sudo tee /etc/sysctl.d/99-mtproxy.conf
sudo sysctl --system- For most ordinary users, this change does not cause any noticeable impact on system operation or performance.
- New processes will never get PID above 65535, which prevents MTProxy crashes.
- Systems with many concurrent processes (tens of thousands) may experience faster PID reuse.
- You do not have to run this command if your container restarts often or your system does not generate very large PIDs — MTProxy will usually work fine.
If MTProxy crashes due to large PIDs, you can consider:
-
Disable automatic config updates
SetCONFIG_UPDATE_INTERVAL=0— MTProxy will run continuously without restarting. -
Use container restart to refresh config
Combine the above with periodic container restart (via Docker restart policy or host cron) to reset PID counters and update config.
This repository packages and runs the official MTProxy binary built from upstream sources.