mysql - docker-compose nodejs 在运行 docker composer 时出错。 MySQL ER_NOT_SUPPORTED_AUTH_MODE

标签 mysql node.js docker docker-compose dockerfile

我正在尝试使用 docker 部署我的 Node js 应用程序,但是当我运行 docker compose 时,它​​在最后给出了一个错误。 我看到了一些解决方案,例如

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password'

,但在 docker 中的何处指定此查询。

docker-compose.yml

version: '3'
services:
  db:
    build:
      context: .
      dockerfile: ./docker/Dockerfile-mysql
    container_name: mydb
    environment:
      - MYSQL_ALLOW_EMPTY_PASSWORD=yes
      - MYSQL_DATABASE=dbautokab
      - MYSQL_USER=root
      - MYSQL_PASSWORD=
    networks:
      - helicopter-network
    healthcheck:
      test: "exit 0"

  helicopter-api:
    build:
      context: .
      dockerfile: ./docker/Dockerfile-api
    depends_on:
      - db
    networks: ['helicopter-network']
    environment:
        - PORT=3000
        - DATABASE_HOST=db
        - DATABASE_PASSWORD=
        - EGG_SERVER_ENV=local
        - NODE_ENV=development
    ports:
      - "3000:3000"

networks:
  helicopter-network:
    driver: bridge

Dockerfile-api

FROM node:10-slim

USER node

RUN mkdir -p /home/node/app

WORKDIR /home/node/app

COPY --chown=node package*.json ./

RUN npm install

COPY --chown=node . .

COPY wait-for-it.sh /

ENV HOST=0.0.0.0 PORT=3000

EXPOSE ${PORT}

CMD /wait-for-it.sh db:3306 -- npm start

Dockerfile-mysql

FROM mysql 

COPY ./docker/init_db.sql /docker-entrypoint-initdb.d/

init_db.sql

CREATE DATABASE IF NOT EXISTS dbautokab;
GRANT ALL PRIVILEGES on dbautokab.*
TO 'root'@'%'
WITH GRANT OPTION;

错误

error when connecting to db: { Error: ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server; consider upgrading MySQL client

最佳答案

当您使用时:

FROM mysql

Docker 拉取最新版本,在这种情况下 (8.0) 不支持身份验证类型

您可以在 Dockerfile 上指定版本标签,例如:

FROM mysql:5.7.26

如果你想留在Mysql 8.0.

您应该在容器内执行此命令行:

docker exec -it container_name mysql -u root -p [root-password] mysql -e "update user set authentication_string=password(''), plugin='mysql_native_password' where user='root';"

或者连接到你的容器并执行命令:

docker exec -it container_name /bin/bash mysql -u root -p [root-password] mysql -e "update user set authentication_string=password(''), plugin='mysql_native_password' where user='root';"

希望对你有帮助

关于mysql - docker-compose nodejs 在运行 docker composer 时出错。 MySQL ER_NOT_SUPPORTED_AUTH_MODE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56647785/

相关文章:

mysql - 如何创建MySQL分层递归查询

caching - 构建集合缓存是一个好习惯吗?

javascript - 是否可以在node.js中为多个独立任务创建多个计时器?

docker - Bitbucket 管道步骤是否连续运行?

mysql - 在 MYSQL 中的特定条件下查找最新日期的记录以及其他相应的值

mysql - 我需要比较两个表中的数据并将它们全部显示在新表中

MySQL时间戳列不更新

javascript - 无法使用 Strongloop 从 s3 获取特定文件

python - LEADER_NOT_AVAILABLE - docker 容器

postgresql - bash脚本在docker容器中有一个postgres数据库