telegram-bot-api icon indicating copy to clipboard operation
telegram-bot-api copied to clipboard

[Question] docker image

Open folt opened this issue 4 years ago • 9 comments

Is there an official telegram-bot-api image for docker? Are there any plans to develop it? thanks for answers

folt avatar Dec 23 '20 07:12 folt

No. See https://github.com/tdlib/telegram-bot-api/pull/9#issuecomment-722374257.

levlam avatar Dec 23 '20 07:12 levlam

No. See #9 (comment).

This clarifies the situation. Maybe you should document this strategy in the documentation?

folt avatar Dec 23 '20 07:12 folt

It is strange to document lack of official support of a third-party tool, even it is so popular as Docker.

levlam avatar Dec 23 '20 08:12 levlam

I managed to build the 54mb docker image with the API server using alpine linux.

Disadvantages:

  • Building docker image requires at least 6GB of RAM
  • Build on 4 CPU + 6GB of RAM takes ~1200 seconds

Pros:

  • Thanks to the multistep build I was able to decrease size from 560MB to 54MB

Will test it for few days and either create PR with Dockerfile or push the image somewhere for everyone to use after I'll set up the build pipeline to sync with changes in this repo :)

lukaszraczylo avatar Dec 27 '20 17:12 lukaszraczylo

Update: Well.. There you have it everyone - freshly baked, minimal docker image for the telegram api server.

  • Instructions are in the README
  • I will add cross compiled version for the Raspberry Pi, possibly after the dinner 👍

https://github.com/lukaszraczylo/tdlib-telegram-bot-api-docker

Update: As I have raspberry pi k8s cluster as well - I decided to add images for the Raspberry Pi / ARM64 as well, then stumbled upon few comments of people requesting them.

lukaszraczylo avatar Dec 27 '20 19:12 lukaszraczylo

Just an example of telegram-bot-api Dockerfile, 56 MB:

FROM alpine:3.19 as builder
# Compile telegram-bot-api server:
RUN apk update && apk upgrade && \
    apk add --update alpine-sdk linux-headers git zlib-dev openssl-dev gperf cmake && \
    git clone --recursive https://github.com/tdlib/telegram-bot-api.git && \
    cd telegram-bot-api && \
    rm -rf build && \
    mkdir build && \
    cd build && \
    cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX:PATH=/usr/local .. && \
    cmake --build . --target install

FROM alpine:3.19

# Install dependencies:
RUN apk update && apk upgrade && apk add --update --no-cache \
    zlib-dev openssl-dev libstdc++

# Install telegram-bot-api server:
COPY --from=builder /usr/local/bin/telegram-bot-api /usr/local/bin/

ENTRYPOINT ["telegram-bot-api", "--api-id=${TELEGRAM_API_ID}", "--api-hash=${TELEGRAM_API_HASH}", "--http-port=8080", "--local"]

CaliforniaMountainSnake avatar Jan 15 '24 20:01 CaliforniaMountainSnake

@lukaszraczylo I didn't see your repo before and I created one for my self 😅.

I saw #9 this comment and I'm not agree. I think we can create differents images for at least 80% of the users.

I will continue improving my image and adding more options

ragnarok22 avatar Feb 27 '24 00:02 ragnarok22

@ragnarok22 By the way, you Dockerfile also has some drawbacks and is worse than many other already existing Dockerfile. All of them can be fixed for sure.

Anyway, creating a Dockerfile for building the executable is a very simple task given existence of https://tdlib.github.io/telegram-bot-api/build.html, but only the end user knows how they want to run the image using Docker and can create corresponding Dockerfile. For example, see https://github.com/aiogram/telegram-bot-api/blob/master/Dockerfile, which is interoperable with official NGINX Docker image.

levlam avatar Feb 27 '24 16:02 levlam

@ragnarok22 By the way, you Dockerfile also has some drawbacks and is worse than many other already existing Dockerfile. All of them can be fixed for sure.

Anyway, creating a Dockerfile for building the executable is a very simple task given existence of https://tdlib.github.io/telegram-bot-api/build.html, but only the end user knows how they want to run the image using Docker and can create corresponding Dockerfile. For example, see https://github.com/aiogram/telegram-bot-api/blob/master/Dockerfile is interoperable with official NGINX Docker image.

Thanks for the feedback. I will use it and improve it over time.

ragnarok22 avatar Feb 27 '24 17:02 ragnarok22