简体   繁体   中英

MySQL dial tcp 172.30.0.3:3306: connect: connection refused

go web app get mysql dial connect err:

docker-compose.yml

version: '3'
services:
  db:
    build:
      context: ./docs/mysql
    environment:
      MYSQL_ROOT_PASSWORD: root
    container_name: puzzle-mysql
    ports:
      - 3306:3306
    tty: true
    restart: always
    networks:
      - puzzle_network
  redis:
    image: redis:6.2.4
    ports:
      - 6379:6379
    container_name: puzzle-redis
    restart: always
    networks:
      - puzzle_network
  server:
    build:
      context: .
    volumes:
      - "./:/workspace"
    container_name: puzzle-server
    environment:
      env: production
    ports:
      - 8081:8081
    tty: true
    restart: on-failure
    depends_on:
      - db
      - redis
    networks:
      - puzzle_network

networks:
  puzzle_network:
    driver: bridge

docker-compose up -d then all containers is running:

containers running

get server error log:

[2022-05-23 07:38:36.544] production.info bootstrap/db.go:37 mysql connect info: {"info": "root:root@tcp(db:3306)/puzzle?charset=utf8mb4&parseTime=True&loc=Local"}

[2022-05-23 07:38:36.546] production.error bootstrap/db.go:52 Mysql connect failed, err: {"err": "dial tcp 172.30.0.3:3306: connect: connection refused"}

mysql contaienr info

help, how to solution?

solved!

Before running the server, you need to wait for the mysql service to be started.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM