mariaDB container connection refused

Hello I wanted to build a new container with my docker-compose.yml and it worked so far:

version: '2.4'

services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
    environment:
      - PORT=8080
    volumes:
      - ../../:/workspaces:cached
   
    command: sleep infinity
  db:
       image: mariadb:11.1
       restart: always
       environment:
         MARIADB_DATABASE: ****
         MARIADB_USER: ****
         MARIADB_PASSWORD: ****
         MARIADB_ROOT_PASSWORD: ****
       volumes:
         - ****DevDB:/var/lib/mysql
  db-testing:
       image: mariadb:11.1
       restart: always
       environment:
         MARIADB_DATABASE: ****-testing
         MARIADB_USER: ****
         MARIADB_PASSWORD: ****
         MARIADB_ROOT_PASSWORD: ****
       volumes:
         - ****TestDB:/var/lib/mysql
       ports:
         - "3309:3306"
volumes:
  ****DevDB:
  ****TestDB:

But I am not able to connect via VSCode and my Plugin to that container. When I try to, I get: “Connection error! connect ECONNREFUSED 172.18.0.2:3309”.
But the container is definately build. And when I call “docker ps” it is listed. And even when I want to get in to that container with “docker exec -it container_name bash” it works. But somehow I cannot connect with my plugin, while I am able all the time to connect to the older container for my productive database. I did the exact same for both.

To my setup:
Everything is hosted on a server and I am connected my terminal and my IDE VSCode to it via SSH. And on that machine are my containers running. So there should not be a problem caused by firewall settings or something like that. Everything is on that machine.

I think it is just a trivial solution, but I really can’t see it and it makes me crazy somehow.

is probably a private IP inside a Docker network, so not reachable from outside. Try to use the host IP to connect.

Try to use localhost:3309

Actually I tried that before too. Forgot to mention that. Localhost doesn’t work either. But what I am confused about is, that for the other connection the servicename was “db” and I don’t know what I do different. Especially because I can edit the existing connection and see what was set up there:

Server Type: MariaDB
Host: db
Port: 3306
Username ****
Password: ****
Database: ****

So for me
Server Type: MariaDB
Host: db-testing
Port: 3309
Username ****
Password: ****
Database: ****-testing

So as far I can see this should work xO