0

I have a problem with mysql 5.7 container denying access to my nodeJS container. I'm using docker-compose and I'm running docker on Ubuntu 18.04 lts.

I apologize for the mistakes in English. This is not my mother language.

I replaced all confidential information with *** and in the images I put a red line

Here's my docker-compose.yml

version: '3.1'

services:  
  db:
    container_name: '***-db'
    image: mysql:5.7
    command: --default-authentication-plugin=mysql_native_password
    restart: always
    environment:
      - MYSQL_ROOT_PASSWORD=***
      - MYSQL_DATABASE=***
      - MYSQL_USER=***
      - MYSQL_PASSWORD=***
      - TZ=America/Sao_Paulo
    command: mysqld --sql_mode="" --character-set-server=utf8 --collation-server=utf8_slovenian_ci --init-connect='SET NAMES UTF8;' --innodb-flush-log-at-trx-commit=0
    ports: 
      - 3306:3306
    volumes:
      - ./db_data:/var/lib/mysql
    network_mode: "host"
  server:
    image: server
    restart: always
    ports:
      - "2000:22"
      - "3000:3000"
    network_mode: "host" 
  front:
    image: portal
    restart: always
    links: 
      - server:server
    ports: 
      - 4200:80

I am using a volume with the database for my mysql container. In this volume I have my user and password set and I also have my schema with every table. I copy everything from this path:

/var/lib/mysql

that I have on my configuration (I am not using docker on this one) in another computer with the same version of mysql and that I know it is working.

Here is my server Dockerfile:

FROM ubuntu:18.04
LABEL maintainer = "***"

LABEL build_date="2020-04-24"
RUN apt-get update && apt-get install -y curl
RUN curl -sL https://deb.nodesource.com/setup_8.x | bash -
RUN apt-get update && apt-get install -y nodejs

#COPY AN CONFIGURATION OF APP
COPY ***-server /home/root/***-server
WORKDIR /home/root/***-server
RUN npm install
 
EXPOSE 22   
EXPOSE 3000
 
CMD ["npm", "start"]
      

Here is my nodeJS file to connect with the mysql:

"use strict";

module.exports = {
    config: {
       connectionLimit : 200,
        host: 'localhost',
        user : '***',
        password : '***',
    database: '***'
    }
}

this is the error mesage that docker compose send to me, when I try to connect: enter image description here

And this is image of the container of the mysql that I am trying to access. I make access to the mysql inside the container using the same user that I am using on the server.

enter image description here

Vitor Gonzaga
  • 23
  • 1
  • 6
  • Does this answer your question? [MySQL Error: : 'Access denied for user 'root'@'localhost'](https://stackoverflow.com/questions/41645309/mysql-error-access-denied-for-user-rootlocalhost) – Kapil Khandelwal Aug 31 '20 at 19:13
  • @KapilKhandelwal Thanks for the link! I will try later, but i do not thing this is will work because inside the container i can access the mysql... Is just my others containers that do not have permission – Vitor Gonzaga Sep 01 '20 at 00:11

0 Answers0