'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:
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"}
help, how to solution?
Solution 1:[1]
solved!
Before running the server, you need to wait for the mysql service to be started.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | tigerCandy |
