Skip to content

How my Gin web app connect to MySql container service? #1126

@leslichase9

Description

@leslichase9

I run my mysql container by below cmd:
docker run -d -i -t --mount type=bind,src=/Users/eysirs/database/mysql,dst=/var/lib/mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql

I run my gin web container by Docker Desktop:

Image

desc:
I can connect to MySql by Navicat and all operation is available.
But my Gin web app can not connect to MySql.

go code:
db, err := xorm.NewEngine("mysql", "root:123456@tcp(localhost:3306)/nices?charset=utf8")
if err != nil {
fmt.Println("something is wrong, err:", err.Error())
}

gin web container shows:
[GIN-debug] Listening and serving HTTP on :8080
insert person throw err: dial tcp [::1]:3306: connect: connection refused
[GIN] 2025/11/26 - 17:50:38 | 200 | 1.55525ms | 142.250.184.145 | POST "/create"

What is wrong?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions