WhatsApp API does not connect to database

I'm a beginner in this area of servers, docker, WhatsApp API, etc.

I need to install it on my GoDaddy VPS. Docker is already installed correctly and so is the whatsapp api, installed and running, as 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 run the command docker-compose -f prod-docker-compose.yml logs > debug_output.txt to put the errors in the file debug_output.txt, it repeatedly presents me with both problems next:

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

Follows my db file.env (with hidden username and password, but 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

Follows my prod-docker-compose file.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 this problem would be?

Taking advantage of the question, How would I test if everything is working ok with the API? In the documentation it says to do health check, which would be a GET request for /v1/health, but would that URL boil down to 107.180.94.5:9090/v1/health? Why did I test with this URL in the postman and gave problem when accessing the page.

Author: Gabriel Queiroz Schicora, 2020-02-14

1 answers

MySQL is not on the same network as your other 2 containers. If it was, you could connect to it from those containers via hostname mysql (the very name of the service, which docker resolves to the correct ip).

By setting the hostname to localhost, you are pointing to the container itself, and not to the mysql container. In docker for Windows and for Mac containers are created with the host host.docker.internal pointing to the host ip (which would solve in the 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 docker containers can access the host, which can be obtained from the ip set on the network 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 )

This ip will probably be 172.17.0.1 and you can use it to set the 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

What will give in the same, but that way you do not need to specify the ip directly in your file settings, and if docker adds host.docker.internal on Linux, it will only change your file docker-compose.yml.

It is interesting to obtain this ip dynamically, but probably setting it statically should not give problems, since it is unlikely to change. Anyway, I believe this change solves the MySQL connection problem you saw in the logs.

As for your 2nd question, I do not know how to answer, since I have never used the Whatsapp API, nor the images you posted (docker.whatsapp.biz/web and docker.whatsapp.biz/coreapp).

 0
Author: Lucas Basquerotto, 2020-02-20 14:58:50