Member-only story
Building Containers Using Docker Compose for Golang Application & MySql Database — Learning Golang
2 min readDec 28, 2020
INTRODUCTION
To learn more about what Docker Compose is, please click here for more information.
CREATING DOCKER-COMPOSE.YML
Now, we will create a new file named docker-compose.yml
as shown in the image below. This file contains the configuration of the web service and the database.
GO SQL CONNECTION
Before we run, don’t forget to change the SQL connection configuration in the connection.go
file according to the Docker Compose configuration earlier.
sqlConn,err := sql.Open("mysql", "user:password@tcp(godockerDB)/dev_apps")
“MYSQL_USER:MYSQL_PASSWORD@tcp(CONTAINER_NAME)/MYSQL_DATABASE”
RUN DOCKER COMPOSE
Next, run the following command to run Docker Compose.
docker-compose up
SETUP SESSION CONEECTION MYSQL