First post here! Trying to connect to a mysql server from docker using golang,gin, and gorm but I'm having issues connecting to the server through gorm.
Here is the error I am getting :
panic: dial tcp: lookup bookstoreDB on 172.22.64.1:53: no such host
Here is how I am trying to initiate the connection through gorm:
func Connect() {
d, err := gorm.Open("mysql", "docker:password@tcp(bookstoreDB)/bookstore")
if err != nil {
panic(err)
}
db = d
}
Here's what my docker-compose.yml file looks like:
version: "3.8"
services:
mysql_server:
image: mysql:8.0
container_name: bookstoreDB
environment:
- MYSQL_DATABASE=bookstore
- MYSQL_USER=docker
- MYSQL_PASSWORD=password
- MYSQL_ROOT_PASSWORD=password
ports:
- "3306:3306"
Here is what appears when I run the "docker-compose ps" command:
Name Command State Ports
-------------------------------------------------------------------------------------
bookstoreDB docker-entrypoint.sh mysqld Up 0.0.0.0:3306->3306/tcp, 33060/tcp
Here is a screenshot of my project structure :
Thank you for your time.