Closed NX-Official closed 1 month ago
Hi!
Just could you get the host?
// Get the mapped port for MySQL.
mysqlPort, err := mysqlContainer.MappedPort(ctx, "3306")
require.NoError(t, err)
// Get the host for MySQL.
mysqlHost, err := mysqlContainer.Host(ctx)
require.NoError(t, err)
// Format the DSN.
dsn := fmt.Sprintf("root:12345678@tcp(%s:%s)/test?charset=utf8mb4&parseTime=True&loc=Local", mysqlHost, mysqlPort.Port())
Oh I am sorry for creating this issue, thanks for help :)
And I hope there can be more examples to help users to use.
Oh I am sorry for creating this issue, thanks for help :)
And I hope there can be more examples to help users to use.
Hey @NX-Official,
No problem, you're so welcome to create all the issues you need. 🤗
Testcontainers version
0.31.0
Using the latest Testcontainers version?
Yes
Host OS
Linux (WSL)
Host arch
x86
Go version
1.22
Docker version
Docker info
What happened?
I want to setup a MySQL environment defined in
docker-compose.yml
, then use GORM to connect it.But it just shutdown after be created, and could not connect.
I tried to add
time.Sleep(10 * time.Second)
before I connect but it is not usefulRelevant log output
Additional information
main_test.go
docker-compose.yml