I just replaced my old company computer for a new one(MACOS), download the projects and now Im trying to connect to mysql docker image but I always get
dial tcp 127.0.0.1:3306: connect: connection refused
In my old computer everything worked correctly but now I've this problem.
My docker compose(Not showing all the content):
version: "3"
services:
mysql:
image: mysql:5.6
ports:
- "3306:3306"
volumes:
- mysql-data:/var/lib/mysql
- ./docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d
environment:
MYSQL_ROOT_PASSWORD: a
LANG: C.UTF-8
adminer:
image: adminer
ports:
- 8082:8080
nginx:
build: ../docker-shared/nginx
ports:
- 443:443
volumes:
- "./nginx_proxy_settings.conf:/etc/nginx/conf.d/nginx_proxy_settings.conf"
volumes:
mysql-data:
So if I do a docker-compose up
everything works, you can check in the next image the Adminer is working with data:
This is my Golang code to connect to mysql:
func main() {
dbConfig := mysql.NewConfig()
dbConfig.User = "root"
dbConfig.Passwd = "a"
dbConfig.Addr = "mysql"
dbConfig.DBName = "company_prod"
db, err := sql.Open("mysql", dbConfig.FormatDSN())
if err != nil {
panic(err)
}
defer db.Close()
}
Do you know what Im doing wrong??
Thank you