A minimal, secure, and production-oriented image for telegram-bot-api - an Telegram Bot API server
1.4K
A minimal, secure, and production-oriented Docker image for telegram-bot-api โ an Telegram Bot API server for creating Telegram Botsโ .
Built as a fully static and semi static binary and shipped in a distroless runtime images, running as non-root by default.
amd64 and arm64.8082).Telegram-bot-api is a Telegram proxy for Bot API. Operating proxies may be restricted or monitored depending on your country/ISP and may carry legal/operational risks.
You are responsible for compliance with local laws and for safe deployment (firewalling, access control, logs, monitoring).
9.4, 9.4-distroless, distroless, latestโ โ 9.4-debian13, 9.4-debian, debian13, debianโ โ 9.4-alpine3.23, 9.4-alpine, alpine3.23, alpineโ โ The telegram-bot-api images come in many flavors, each designed for a specific use case.
telegram-bot-api:<version>-distroless-ccThis is the defacto image. If you are unsure about what your needs are, you probably want to use this one.
Image based on debian for build stage and gcr.io/distroless/cc:nonroot for runtime.
telegram-bot-api:<version>-debianThis image is based on the Debian projectโ โ , available in the debian official imageโ . Used Debian Linux slim tag, that is much smaller than others, and thus leads slimmer images in general.
This image contains some additional tools, like ping, telnet, curl, etc. to connectivity checks.
telegram-bot-api:<version>-alpineThis image is based on the popular Alpine Linux projectโ โ , available in the alpine official imageโ . Alpine Linux is much smaller than most distribution base images (~5MB), and thus leads to much slimmer images in general.
This variant is useful when final image size being as small as possible with additional is your primary concern. The main caveat to note is that it does use musl libcโ โ instead of glibc and friendsโ โ , so performance may be lower if depending on the depth of libc requirements/assumptions. See this Hacker News comment threadโ โ for more discussion of the issues that might arise and some pro/con comparisons of using Alpine-based images.
This image contains some additional tools, like ping, telnet, curl, etc. to connectivity checks.
Go to my.telegram.orgโ create application if not exists and obtain App api_id and App api_hash
.env with values from first stepTELEGRAM_API_ID=1234567
TELEGRAM_API_HASH=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Place your configuration file as ./.env.
docker-compose.ymlNote: the container runs as non-root, but telegram-bot-api can binds to 443.
To allow binding to privileged ports, you can addNET_BIND_SERVICE.
---
services:
telegram-bot-api:
container_name: telegram-bot-api
image: "raylabpro/telegram-bot-api:${TGBOTAPI_TAG:-distroless}"
restart: "unless-stopped"
pull_policy: "always"
# network_mode: host
ports:
- "18081:8081"
- "127.0.0.1:8082:8082/tcp"
ulimits:
nofile:
soft: 65536
hard: 65536
env_file: ".env"
environment:
TZ: "Europe/Moscow"
TELEGRAM_API_ID: ${TELEGRAM_API_ID}
TELEGRAM_API_HASH: ${TELEGRAM_API_HASH}
command:
- --http-port=8081
- --http-stat-port=8082
- --data-dir=/var/lib/telegram-bot-api
- --temp-dir=/tmp
- --local
volumes:
- "/etc/timezone:/etc/timezone:ro"
- "/etc/localtime:/etc/localtime:ro"
- "/etc/hostname:/etc/hostname:ro"
- "tg-data:/var/lib/telegram-bot-api"
- "tg-logs:/var/log/telegram-bot-api"
- "tg-tmp:/tmp"
# Hardening
security_opt:
- no-new-privileges:true
cap_drop:
- ALL
cap_add:
- NET_BIND_SERVICE
# read_only: true
# tmpfs:
# - /tmp:rw,nosuid,nodev,noexec,size=16m
# - /var/lib/telegram-bot-api:rw,nosuid,nodev,noexec,size=256m
# - /var/log/telegram-bot-api:rw,nosuid,nodev,noexec,size=2048m
# Resource limits (optional)
deploy:
resources:
limits:
cpus: "0.50"
memory: 256M
logging:
driver: json-file
options:
max-size: "10m"
max-file: "3"
volumes:
tg-data:
tg-logs:
tg-tmp:
docker compose up -d
Logs:
docker compose logs -f
| Variable | Mandatory | Default | Description |
|---|---|---|---|
TELEGRAM_API_ID | Yes (if not used --api-id arg) | โ | Application identifier for Telegram API access, which can be obtained at https://my.telegram.orgโ . |
TELEGRAM_API_HASH | Yes (if not used --api-hash arg) | โ | Application identifier hash for Telegram API access, which can be obtained at https://my.telegram.orgโ . |
| Argument | Mandatory | Default | Description |
|---|---|---|---|
--api-id=<arg> | Yes (if not used TELEGRAM_API_ID env) | โ | Application identifier for Telegram API access, which can be obtained at https://my.telegram.orgโ . |
--api-hash=<arg> | Yes (if not used TELEGRAM_API_HASH env) | โ | Application identifier hash for Telegram API access, which can be obtained at https://my.telegram.orgโ . |
--local | No | โ | Allow the Bot API server to serve local requests. |
-p, --http-port=<arg> | No | 8081 | HTTP listening port. |
-s, --http-stat-port=<arg> | No | โ | HTTP statistics port. |
-d, --dir=<arg> | No | โ | Server working directory. |
-t, --temp-dir=<arg> | No | โ | Directory for storing HTTP server temporary files. |
--filter=<arg> | No | โ | <remainder>/<modulo>. Allow only bots with bot_user_id % modulo == remainder. |
--max-webhook-connections=<arg> | No | โ | Default value of the maximum webhook connections per bot. |
--http-ip-address=<arg> | No | โ | Local IP address, HTTP connections to which will be accepted. By default, connections to any local IPv4 address are accepted. |
--http-stat-ip-address=<arg> | No | โ | Local IP address, HTTP statistics connections to which will be accepted. By default, statistics connections to any local IPv4 address are accepted. |
-l, --log=<arg> | No | โ | Path to the file where the log will be written. |
-v, --verbosity=<arg> | No | โ | Log verbosity level. |
--memory-verbosity=<arg> | No | 3 | Memory log verbosity level. |
--log-max-file-size=<arg> | No | 2000000000 | maximum size of the log file in bytes before it will be auto-rotated. |
-u, --username=<arg> | No | โ | Effective user name to switch to. |
-g, --groupname=<arg> | No | โ | effective group name to switch to. |
-c, --max-connections=<arg> | No | โ | maximum number of open file descriptors. |
--cpu-affinity=<arg> | No | all available CPUs | CPU affinity as 64-bit mask. |
--main-thread-affinity=<arg> | No | value of the option --cpu-affinity | CPU affinity of the main thread as 64-bit mask. |
--proxy=<arg> | No | โ | HTTP proxy server for outgoing webhook requests in the format http://host:portโ . |
| Container Path | Purpose |
|---|---|
/var/lib/telegram-bot-api | Folder to store bot-api data (could be set with --dir argument) |
/var/log/telegram-bot-api | Folder to store logs if it enabled with --log argument |
/tmp | Folder to store temporary files (could be set with --temp argument) |
| Port | Purpose |
|---|---|
8081/tcp | Main listener for bot-api clients connection. |
8082/tcp | Metrics port (only if enabled in args). |
/usr/local/bin/telegram-bot-api["--local", "--http-port=8081", "--http-stat-port==8082", "--dir=/var/lib/telegram-bot-api", "--temp-dir=/tmp"]So the container effectively runs:
/usr/local/bin/telegram-bot-api --local --http-port=8081 --http-stat-port==8082 --dir=/var/lib/telegram-bot-api --temp-dir=/tmp
To use a different arguments, override the command:
docker run ... raylabpro/telemt:latest --local --http-port=18081 --http-stat-port==28082 --dir=/var/lib/telegram-bot-api --temp-dir=/tmp
Content type
Image
Digest
sha256:7d0ebc40bโฆ
Size
61.5 MB
Last updated
5 months ago
docker pull raylabpro/telegram-bot-api:debian