I am trying to deploy my node js application with docker but when I am running the docker compose it giving an error at the end. I saw some solution like
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password'
, but where to specify this query in the 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
error when connecting to db: { Error: ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server; consider upgrading MySQL client
Santiago Trujillo
I believe that starting the server with a custom default authentication plugin should do the trick. In this case, you can override the command
property in docker-compose.yml
.
# ...
services:
db:
# ...
command: --default-authentication-plugin=mysql_native_password
# ...
When you use:
FROM mysql
Docker pull the latest version, in this case (8.0) that does not support type of authentication
You can specify version tag on you Dockerfile like :
FROM mysql:5.7.26
If you want to stay in Mysql 8.0.
You should execute this command line inside container:
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';"
Or connect to your container and execute the command:
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';"
Hope it helps