0

I have 2 dockers composes. 1 implements an infrastructure with a reverse proxy, databases, database admins, etc.

version: '3.7'

volumes:
  mysql80_volume:
    name: MySql80-Volume

services:
  reverse-proxy:
    image: traefik:v2.2
    container_name: "reverse-proxy"
    restart: always
    network_mode: bridge
    ports:
      - "80:80"
      - "443:443"
    # etc...

  mysql80:
    container_name: mysql80
    image: mysql:8.0
    restart: always
    labels:
      - traefik.enable=false
    network_mode: bridge
    ports:
      - 3380:3306
    environment:
      - MYSQL_ROOT_PASSWORD=root
      - MYSQL_PASSWORD=root
    volumes:
      - mysql80_volume:/var/lib/mysql
      - ./my.cnf:/etc/my.cnf

And there is a docker-compose service, which describes the configs for the service.

version: '3.7'
services:
    server:
        container_name: project-api.com
        build:
            context: .
            dockerfile: docker/Dockerfile
        sysctls:
            - net.ipv4.ip_unprivileged_port_start=0
        restart: always
        labels:
            - traefik.enable=true
            #labels for traefik
        extra_hosts:
            - "project-api.com www.project-api.com:127.0.0.1"
        external_links:
            - mysql80:mysql # <---- My link
        network_mode: bridge
        volumes:
            - .:/app

I want to connect the database from docker-compose 1 to the docker-compose 2 file and pass it to the connection in the Typeform config.

Config for typeorm

    type: "mysql",
    host: process.env.TYPEORM_ENDPOINT,
    database: process.env.TYPEORM_DB_NAME,
    port: parseInt(process.env.TYPEORM_PORT) || 3306,
    username: process.env.TYPEORM_USERNAME,
    password: process.env.TYPEORM_PASSWORD,

.env

TYPEORM_ENDPOINT=mysql
TYPEORM_DB_NAME=red_driver
TYPEORM_USERNAME=root
TYPEORM_PASSWORD=root
TYPEORM_PORT=3306

But I am getting an error.

project-api.com  | [nodemon] 2.0.7
project-api.com  | [nodemon] to restart at any time, enter `rs`
project-api.com  | [nodemon] watching path(s): *.*
project-api.com  | [nodemon] watching extensions: ts,graphql
project-api.com  | [nodemon] starting `ts-node index.ts`

project-api.com  | Error: getaddrinfo ENOTFOUND mysql
project-api.com  |     at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:71:26)
project-api.com  |     --------------------
project-api.com  |     at Protocol._enqueue (/home/app/node_modules/mysql/lib/protocol/Protocol.js:144:48)
project-api.com  |     at Protocol.handshake (/home/app/node_modules/mysql/lib/protocol/Protocol.js:51:23)
project-api.com  |     at PoolConnection.connect (/home/app/node_modules/mysql/lib/Connection.js:116:18)
project-api.com  |     at Pool.getConnection (/home/app/node_modules/mysql/lib/Pool.js:48:16)
project-api.com  |     at /home/app/src/driver/mysql/MysqlDriver.ts:894:18
project-api.com  |     at new Promise (<anonymous>)
project-api.com  |     at MysqlDriver.createPool (/home/app/src/driver/mysql/MysqlDriver.ts:891:16)
project-api.com  |     at MysqlDriver.<anonymous> (/home/app/src/driver/mysql/MysqlDriver.ts:344:36)
project-api.com  |     at step (/home/app/node_modules/typeorm/node_modules/tslib/tslib.js:141:27)
project-api.com  |     at Object.next (/home/app/node_modules/typeorm/node_modules/tslib/tslib.js:122:57) {
project-api.com  |   errno: -3008,
project-api.com  |   code: 'ENOTFOUND',
project-api.com  |   syscall: 'getaddrinfo',
project-api.com  |   hostname: 'mysql',
project-api.com  |   fatal: true
project-api.com  | }

  • Does the setup described in [Communication between multiple docker-compose projects](https://stackoverflow.com/questions/38088279/communication-between-multiple-docker-compose-projects) work for you? I'd avoid the obsolete `external_links:` option. – David Maze Apr 06 '22 at 16:47
  • @DavidMaze Could you help me, what should I change to make it work in my case? – Donnie Darko Apr 06 '22 at 16:55

1 Answers1

1

The config property of typeorm must be the container name of MySQL. (host: 'mysql80')

Lucas Gama
  • 11
  • 1
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Apr 23 '22 at 08:56