Docker compose dependant service ip and port is not accessible

I'm trying to run an integration service example(github here) with below docker compose file which has a mysql service as a dependency for the main service

version: '2'

  db:
    image: mysql:8.0
    cap_add:
      - SYS_NICE
    restart: always
    environment:
      - MYSQL_DATABASE=events
      - MYSQL_ROOT_PASSWORD=root
      - MYSQL_USER=events
      - MYSQL_PASSWORD=events
    ports:
      - '3306:3306'
    volumes:
      - ./db/mysql:/var/lib/mysql

  webhooks_web:
    env_file:
      - .env
    environment:
      KAFKA_BROKER_LIST: kafka:9092
      KAFKA_GROUP_ID: events
      EVENT_TOPIC: events
      MYSQL_HOST: db
      MYSQL_DATABASE: events
      MYSQL_USER: events
      MYSQL_PASSWORD: events
    build:
      context: .
      dockerfile: Dockerfile
    volumes:
      - ./src/js/:/app/js/
      - ./src/public/:/app/public/
      - ./src/views/:/app/views/
      - ./index.js:/app/index.js
      - ./db:/app/db
      - ./tools:/app/tools
    ports:
      - 3000:3000
    command: ./tools/wait-for-it.sh db:3306 -t 60 --strict -- npm run dev
    depends_on:
      - db

This use the wait-for-it script to wait till mysql comes up. Script fails saying

wait-for-it.sh: timeout occurred after waiting 60 seconds for db:3306

My doubt is that the host name db doesn't get resolved into a ip. I'm not sure how this works but I checked the /etc/hosts file but that dns doesn't get added to there.

What is the problem here?

P.S - Log from the db service says it is ready to accept connections.

db_1            | 2023-03-19T09:32:50.788673Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
db_1            | 2023-03-19T09:32:51.340528Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
db_1            | 2023-03-19T09:32:51.340583Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
db_1            | 2023-03-19T09:32:51.343906Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
db_1            | 2023-03-19T09:32:51.408233Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.32'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  MySQL Community Server - GPL.
db_1            | 2023-03-19T09:32:51.408208Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/run/mysqld/mysqlx.sock

I can docker-compose exec db /bin/bash and use mysql -u events -p and log in to the server

My OS is Ubuntu 22.04 and docker version is 23.0.1, build a5ee5b1



Comments

Popular posts from this blog

Today Walkin 14th-Sept

Spring Elasticsearch Operations

Hibernate Search - Elasticsearch with JSON manipulation