raylabpro/telegram-bot-api

By raylabpro

โ€ขUpdated 5 months ago

A minimal, secure, and production-oriented image for telegram-bot-api - an Telegram Bot API server

Image
Networking
Integration & delivery
API management
1

1.4K

raylabpro/telegram-bot-api repository overview

โ telegram-bot-api

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.


โ โœจ Features

  • ๐Ÿ” Secure by default: Distroless runtime + non-root user.
  • ๐Ÿ“ฆ Extended but secure variant: based on Debian and Alpine with additional network tools + non-root user.
  • ๐Ÿ— Multi-arch: Supports amd64 and arm64.
  • ๐Ÿ“ˆ Metrics-ready: Supports metrics port (8082).

โ โš ๏ธ Important Notice

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).



โ ๐Ÿ“” Image Variants

The telegram-bot-api images come in many flavors, each designed for a specific use case.

โ telegram-bot-api:<version>-distroless-cc

This 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>-debian

This 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>-alpine

This 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.


โ ๐Ÿš€ Quick Start (Docker Compose)

โ 1. Get api_id and api_hash

Go to my.telegram.orgโ  create application if not exists and obtain App api_id and App api_hash

โ 2. Create .env with values from first step
TELEGRAM_API_ID=1234567
TELEGRAM_API_HASH=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Place your configuration file as ./.env.

โ 3. Create docker-compose.yml

Note: the container runs as non-root, but telegram-bot-api can binds to 443.
To allow binding to privileged ports, you can add NET_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:
โ 4. Start
docker compose up -d

Logs:

docker compose logs -f

โ โš™๏ธ Configuration

โ Environment Variables
VariableMandatoryDefaultDescription
TELEGRAM_API_IDYes (if not used --api-id arg)โ€”Application identifier for Telegram API access, which can be obtained at https://my.telegram.orgโ .
TELEGRAM_API_HASHYes (if not used --api-hash arg)โ€”Application identifier hash for Telegram API access, which can be obtained at https://my.telegram.orgโ .
โ Shell args
ArgumentMandatoryDefaultDescription
--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โ .
--localNoโ€”Allow the Bot API server to serve local requests.
-p, --http-port=<arg>No8081HTTP 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>No3Memory log verbosity level.
--log-max-file-size=<arg>No2000000000maximum 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>Noall available CPUsCPU affinity as 64-bit mask.
--main-thread-affinity=<arg>Novalue of the option --cpu-affinityCPU 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โ .
โ Volumes
Container PathPurpose
/var/lib/telegram-bot-apiFolder to store bot-api data (could be set with --dir argument)
/var/log/telegram-bot-apiFolder to store logs if it enabled with --log argument
/tmpFolder to store temporary files (could be set with --temp argument)
โ Ports
PortPurpose
8081/tcpMain listener for bot-api clients connection.
8082/tcpMetrics port (only if enabled in args).

โ ๐Ÿง  Container Behavior

  • ENTRYPOINT: /usr/local/bin/telegram-bot-api
  • CMD (default): ["--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

Tag summary

Content type

Image

Digest

sha256:7d0ebc40bโ€ฆ

Size

61.5 MB

Last updated

5 months ago

docker pull raylabpro/telegram-bot-api:debian