Host ‘172.19.0.5’ is not allowed to connect to this MySQL server [duplicate]

  docker, docker-compose, mysql, node.js

My app uses react as the fronend,node as the backend and mysql as the database. The code is working fine when ran directly using npm, but facing problems while dockerizing it.I have created a single docker-compose file and when executing docker-compose up command the node server is getting this error while trying to create a connection with mysql server:

code: 'ER_HOST_NOT_PRIVILEGED',
errno: 1130,
sqlMessage: "Host '172.19.0.5' is not allowed to connect to this MySQL server",
sqlState: undefined,
fatal: true

My docker-compose file is:

version: '3'
services:
    mysql:
        image: mysql:latest
        command: --default-authentication-plugin=mysql_native_password
        restart: always
        environment:
          MYSQL_ROOT_PASSWORD: my_pass
          MYSQL_DATABASE: my_db
    redis:
        image: 'redis:latest'
    api:
        build:
            dockerfile: Dockerfile.dev
            context: ./server
        volumes: 
            - /app/node_modules
            - ./server:/app
        depends_on:
           - mysql
        environment: 
            - CACHE_HOST=redis
            - CACHE_PORT=6379
            - DB_USERNAME=root
            - HOST=mysql
            - DB_NAME=my_db
            - DB_PASSWORD=my_pass
            - DB_PORT=3306
    client:
        stdin_open: true
        build: 
            dockerfile: Dockerfile.dev
            context: ./client
        volumes: 
            - /app/node_modules
            - ./client:/app
    nginx:
        depends_on:
            - api
            - client
        restart: always
        build:
            dockerfile: Dockerfile.dev
            context: ./nginx
        ports:
            - "8080:80"

–> docker ps is showing every container is running fine


CONTAINER ID   IMAGE                       COMMAND                  CREATED        STATUS          PORTS                                   NAMES
7cbd9c9a25f8   my_app_docker_nginx    "/docker-entrypoint.…"   14 hours ago   Up 37 seconds   0.0.0.0:8080->80/tcp, :::8080->80/tcp   my_app_docker_nginx_1
360363cd667c   my_app_docker_api      "docker-entrypoint.s…"   14 hours ago   Up 39 seconds                                           my_app_docker_api_1
31edccd4aae5   mysql:latest           "docker-entrypoint.s…"   14 hours ago   Up 41 seconds   3306/tcp, 33060/tcp                     my_app_docker_mysql_1
9343a028da23   redis:latest           "docker-entrypoint.s…"   15 hours ago   Up 42 seconds   6379/tcp                                my_app_docker_redis_1
b61b6bdb3b63   my_app_docker_client   "docker-entrypoint.s…"   15 hours ago   Up 41 seconds                                           my_app_docker_client_1

The containers are up and running, but mysql is not accepting connections.

Source: Docker Questions

LEAVE A COMMENT