Node app unable to see mysql or mysql-lb in same stack

Hi all,
I’ve got a node app (mysql-updater) that connects, using the mysql2 module, to the mysql container if I supply the containers IP address.

However, if I try to use the link servicename of “mysql”, which points to the mysql-lb, I get

Error: getaddrinfo ENOTFOUND mysql mysql:3306

Here is my docker-compose file, which you can see includes the “links” config item for the mysql-updater container. Can anyone point out something I’m doing wrong?

version: '2'
services:
  mysql-lb:
    image: rancher/lb-service-haproxy:v0.6.4
    ports:
    - 3306:3306/tcp
    labels:
      io.rancher.scheduler.affinity:host_label: database=yes
      io.rancher.container.agent.role: environmentAdmin
      io.rancher.container.create_agent: 'true'
  mysql:
    image: mariadb:10.3.0
    environment:
      MYSQL_DATABASE: xxx
      MYSQL_PASSWORD: xxx
      MYSQL_ROOT_PASSWORD: xxx
      MYSQL_USER: xxx
    stdin_open: true
    tty: true
    volumes_from:
    - mysql-data
    labels:
      io.rancher.scheduler.affinity:host_label: database=yes
      io.rancher.sidekicks: mysql-data
  mysql-data:
    image: busybox
    volumes:
    - /mnt/xxx/database:/var/lib/mysql
    labels:
      io.rancher.scheduler.affinity:host_label: database=yes
      io.rancher.container.start_once: 'true'
  mysql-updater:
    image: xxx/mysql_update
    stdin_open: true
    tty: true
    links:
    - mysql-lb:mysql
    labels:
      io.rancher.container.pull_image: always
      io.rancher.scheduler.affinity:host_label: database=yes

Just as an addition to this, I have another node server running on a different stack, which CAN see the mysql database:
The only thing I can see different is that the working container is using external_links rather than links. However, I tried copying the failing container into the other stack, and it still failed with the same error.

version: '2’
services:
ControlPanel:
image:XXX/controlpanel
stdin_open: true
tty: true
labels:
io.rancher.container.pull_image: always
io.rancher.scheduler.affinity:host_label: controlpanel=yes
API:
image: XXX/api
stdin_open: true
external_links:
- Database/mysql-lb:mysql
volumes:
- lets-encrypt:/etc/letsencrypt
tty: true
labels:
io.rancher.container.pull_image: always
io.rancher.scheduler.affinity:host_label: api=yes

Something else I’ve tried -maybe it was a timing issue. The failing script is much simpler, and tries to connect to mysql immediately. The working script does alot of other things first,including setting up an express server.

However, even if I start the container manually via docker CLI, then build-in a 20 second wait within the script before it calls mysql, it still returns ENOTFOUND.

Oh my god, ignore me. When I checked the docker logs, as opposed to the node output, the script is running fine! Essentially, the script checks a value in the database and responds accordingly., and it’s able to return the value successfully.

I’ve got no idea why node is still returning the ENOTFOUND error. I’ll investigate further and share here if I find anything,