xtrime-ru / TelegramApiServer

Fast, simple, async php telegram api server: MadelineProto + Amp HTTP Server
https://tg.i-c-a.su
MIT License
529 stars 116 forks source link

Multi Docker issue #111

Closed litasskuris closed 1 year ago

litasskuris commented 1 year ago

Hi. Can you help me with docker? I try to create multi docker exception:

docker-compose.yml version: '2.4' services: telegram-api-server: image: xtrime/telegram-api-server:latest build: context: . dockerfile: Dockerfile container_name: telegram-api-server restart: unless-stopped ports:

If I try to create dockers from docker-compose.yml I get the mistake "Couldnt connect to MadelineProto" if I know I have to override ENTRYPOINT? But how? What other do I have to pass to docker? And if I understand correctly I can not use the database. So dont I need to create mysql docker in that case?

xtrime-ru commented 1 year ago

Hi!

All your containers need to be in one network with mysql container. So dont change network name, just use different "container_name" and ports, as you did. Probably you need to redefine entrypoint because each container will try to start all sessions. use something like this: entrypoint: "docker-compose-wait && nice -n 20 php server.php -e=.env.docker --docker -s=session_1" entrypoint: "docker-compose-wait && nice -n 20 php server.php -e=.env.docker --docker -s=session_2" ...

And you will need to start interactively, because if you define session it will create it and start athorization process. So you will need interactive mode to enter phone number...

Its totally ok to use multiple containers with one mysql. But make sure you use different accounts. Because one account always stored in one table and eventually you will be using one session in multiple instances and it will not work.

litasskuris commented 1 year ago

thanks for asking. I tried to do process like you said. But there are nothing good results. Something like this: version: '2.4' services: telegram-api-server: image: xtrime/telegram-api-server:latest build: context: . dockerfile: Dockerfile container_name: telegram-api-server restart: unless-stopped ports:

I got that mistake again: tg

This looks like what container started first of all it works correctly but another containers fail with an error

Also I didn`t override entrypoint. As I understand correctly it have to work well without overriding (just only for testing. I get it that for future I need to override it)

litasskuris commented 1 year ago

I`ve seen all containers tries to get session when it is exists. And it blocks access to another containers when one of them got access to session. When I start docker-compose with empty session folder it works correctly (I can create different sessions and work with its) until I recreate docker containers and its fault. I think it needs to define volume session for each container. How can I do it?

xtrime-ru commented 1 year ago

As i said you can define wich session start in entrypoint. By default -s=* which means start all. If you want different session folders you can use somthing like this:

 volumes: 
    - ./:/app-host-link
    - ./sessions/container_1/:./:/app-host-link/sessions
...
 volumes: 
    - ./:/app-host-link
    - ./sessions/container_2/:./:/app-host-link/sessions
...
 volumes: 
    - ./:/app-host-link
    - ./sessions/container_3/:./:/app-host-link/sessions
litasskuris commented 1 year ago

As i said you can define wich session start in entrypoint. By default -s=* which means start all. If you want different session folders you can use somthing like this:

 volumes: 
    - ./:/app-host-link
    - ./sessions/container_1/:./:/app-host-link/sessions
...
 volumes: 
    - ./:/app-host-link
    - ./sessions/container_2/:./:/app-host-link/sessions
...
 volumes: 
    - ./:/app-host-link
    - ./sessions/container_3/:./:/app-host-link/sessions

thanks so match. Ive done it. Everything is working well. But Ive edited this a little bit: ./sessions/container_3/:/app-host-link/sessions

xtrime-ru commented 1 year ago

Ive refactored docker-compose. Now you can define session name in command. And also you can use docker-compose.override.yml to add new servers.