gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 03:15:55 25 4
gpt4 key购买 nike

我正在尝试使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com