How my Gin web app connect to MySql container service? #1127
leslichase9
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
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:
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?
Beta Was this translation helpful? Give feedback.
All reactions