Hello and first of all thank you for your great work!
This package is really pleasant to use even with no prior expirience in building Telegram bots.
Recently i was trying to package my bot inside docker container and faced some strange behaviour.
What expected: compiled binary of the bot could be run inside docker container.
What got: container builds and runs with no errors but the bot is not responding to updates.
Steps to reproduce with code from
- build binary on the host as usual:
go build -v -o test
- test if our bot works when running on host:
export TELEGRAM_TOKEN=realTelegramTokenHere && ./test
In my tests this works and the bot replies to messages.
If the bot works correctly on the host, we can proceed to the next step.
- write simple Dockerfile in the same directory as binary:
COPY ./test ./test
I'm using Ubuntu as my OS so the same binary could be run on the host and in container. If host OS is not GNU/Linux we need to use two stage Dockerfile to build inside temporary container:
FROM golang AS buildstage
COPY *.go go.mod ./
RUN go mod tidy && go build -v -o /out/test .
COPY --from=buildstage /out/test ./test
and build the container:
docker build --no-cache -t testbot .
4. now we can test if the bot works from container:
docker run --name=testbot --rm -it -e TELEGRAM_TOKEN=realTelegramTokenHere testbot
When running inside the container bot does not replies to messages even if we use the binary that works on the host machine.
Tried different hosts, changing docker network settings to
--network=host but no luck.
Since we are using ubuntu container it is possible to exec bash in it, install curl and try to make direct requests to Telegram api.
In my tests
getUpdates requests work perfectly so this should be not network related issue.