Questions about connecting to the database in docker-compose

as shown in the figure, this is the docker-compose configuration file
clipboard.png

clipboard.png

dockerredis-climysqlredis mysql

clipboard.png

clipboard.png

webmysql:

clipboard.png

webhostdocker-composeservice

clipboard.png

but it doesn"t help. I still reported the mistake in the picture. I"ve been entangled for a day, asking for help

.

now the latest image of mysql is 8.0. It is recommended to try 5.7.22. In addition, it is recommended to use the network alias direct alias as the connection target host in compose to use the dns maintained in docker's network

.

if you troubleshoot your problems, go to the service name of mysql under ping in the web container to see if ip is returned, or docker run-ti-- rm-- net:container:web container id zhangguanzhang/alpine sh to use the web container with the same network namespace to troubleshoot
and see if telnet mysql 3389 can get through


error message "Client does not support authentication protocol".
look at your configuration. There should be something wrong with your server configuration in node web. Your mysql configuration has root users and passwords. It is recommended that you write all these in your nodejs configuration.

you can also create users and passwords through mysql links. The following example code


docker-compose networks :

version: '3'
services: 
  web:
    networks: -sharp 
      - my-network
      
  mysql:
    networks: -sharp 
      - my-network
          
networks:          
  my-network:      
Menu