Whatsapp API does not connect to database

Asked

Viewed 387 times

0

I am beginner in this area of servers, Docker, Whatsapp API, etc.

I need to install it in my Godaddy VPS. The Docker is already installed correctly and the Whatsapp api is also installed and running, as shown in the result of the command docker-compose -f prod-docker-compose.yml ps:

Name                  Command               State                   Ports
----------------------------------------------------------------------------------------------
biz_wacore_1   /opt/whatsapp/bin/wait_on_ ...   Up      6250/tcp, 6251/tcp, 6252/tcp, 6253/tcp
biz_waweb_1    /opt/whatsapp/bin/wait_on_ ...   Up      0.0.0.0:9090->443/tcp

And also the result of the command docker ps:

CONTAINER ID        IMAGE                                 COMMAND                  CREATED             STATUS            PORTS                   NAMES
3bde309754e9        docker.whatsapp.biz/web:v2.27.8       "/opt/whatsapp/bin/w…"   2 hours ago         Up 2 hours            0.0.0.0:9090->443/tcp   biz_waweb_1
cc8371b45075        docker.whatsapp.biz/coreapp:v2.27.8   "/opt/whatsapp/bin/w…"   2 hours ago         Up 2 hours            6250-6253/tcp           biz_wacore_1
4110a5ed2727        mysql/mysql-server:5.7.29-1.1.15      "/entrypoint.sh mysq…"   2 hours ago         Up 2 hours(healthy)   3306/tcp, 33060/tcp     mysql1

But when I execute the command docker-compose -f prod-docker-compose.yml logs > debug_output.txt to put the errors in the file debug_output.txt, repeatedly presents me with the following two problems::

waweb_1   | MySQL is not up yet - sleeping
wacore_1  | MySQL is not up yet - sleeping

Follow my db.env file (with hidden user and password, but they are correct):

# Copyright (c) Facebook, Inc. and its affiliates.
# This source code is licensed under the MIT license found in the# LICENSE file in the root directory of this source tree.
WA_DB_ENGINE=MYSQL
WA_DB_HOSTNAME=localhost
WA_DB_PORT=3306
WA_DB_USERNAME=***********
WA_DB_PASSWORD=***********
WA_DB_CONNECTION_IDLE_TIMEOUT=180

Follow my file Prod-Docker-Compose.yml:

# Copyright (c) Facebook, Inc. and its affiliates.

# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

version: '3'

volumes:
  whatsappMedia:
    driver: local

services:
  wacore:
    image: docker.whatsapp.biz/coreapp:v2.27.8
    command: ["/opt/whatsapp/bin/wait_on_mysql.sh", "/opt/whatsapp/bin/launch_within_docker.sh"]
    volumes:
     - whatsappMedia:/usr/local/wamedia
    env_file:
      - db.env
    environment:
      # This is the version of the docker templates being used to run WhatsApp Business API
      WA_RUNNING_ENV_VERSION: v2.2.3
      ORCHESTRATION: DOCKER-COMPOSE
    network_mode: bridge
  waweb:
    image: docker.whatsapp.biz/web:v2.27.8
    command: ["/opt/whatsapp/bin/wait_on_mysql.sh", "/opt/whatsapp/bin/launch_within_docker.sh"]
    ports:
     - "9090:443"
    volumes:
     - whatsappMedia:/usr/local/wamedia
    env_file:
      - db.env
    environment:
      WACORE_HOSTNAME: wacore
      # This is the version of the docker templates being used to run WhatsApp Business API
      WA_RUNNING_ENV_VERSION: v2.2.3
      ORCHESTRATION: DOCKER-COMPOSE
    depends_on:
      - "wacore"
    links:
      - wacore
    network_mode: bridge

Can anyone tell me what that problem would be?

Taking advantage of the question, how would I test if everything is working ok with the API? The documentation says to do the health check, which would be a GET request to /v1/health, but this URL would be summarized in 107.180.94.5:9090/v1/health? Why I tested with this URL in Postman and gave problem when accessing the page.

1 answer

0

Mysql is not on the same network as its other 2 containers. If he was, you could connect to him from those containers through the hostname mysql (the service name itself, which Docker resolves to the correct ip).

Setting the hostname to localhost, you are pointing to the container itself, not the mysql container. In Docker for Windows and Mac containers are created with the host host.docker.internal pointing to the host ip (which would solve in your case).

Unfortunately Docker does not have a way to specify this ip yet on Linux, but I believe that in the next version you will already have this possibility, as you can see in this pull request: https://github.com/moby/moby/pull/40007

At the moment, what you can do is get the ip through which the Docker containers can access the host, which can be obtained from the network-defined ip docker0:

ip route | grep docker0 | awk '{print $9}'

(this is just one of the ways to get this ip, as you can see in https://github.com/docker/for-linux/issues/264)

That ip will probably be 172.17.0.1 and you can use it to set hostname:

WA_DB_HOSTNAME=172.17.0.1

If you prefer to use host.docker.internal even now, you can specify for each of your 2 services:

    extra_hosts:
    - "host.docker.internal:172.17.0.1"

and then:

WA_DB_HOSTNAME=host.docker.internal

which will give in the same, but this way you do not need to specify the ip directly in your settings file, and in case the Docker add host.docker.internal on Linux, just change your file docker-compose.yml.

It is interesting to get this ip dynamically, but probably defining it statically should not give problems, as it is unlikely to change. Anyway, I think this change solves the connection problem with Mysql that you saw in the logs.

As for your second question, I do not know answer, since I never used the Whatsapp API, and neither the images you posted (docker.whatsapp.biz/web and docker.whatsapp.biz/coreapp).

Browser other questions tagged

You are not signed in. Login or sign up in order to post.