I have a database docker that we'll call mariadb and I also have an web docker that uses golang. What I'm trying to do is connect the two dockers using compose, but in my golang code, I have to know the database docker's ip address ahead of time.
Golang main.go:
db, err := sql.Open("mysql",
"root:passsword@tcp(<should_be_database_docker_ip>:3306)/database")
Docker-compose.yml
version: '3'
services:
web:
image: web_docker
ports:
- "8080"
depends_on:
- database
database:
image: mariadb
ports:
- "3306"
environment:
- MYSQL_ROOT_PASSWORD=password
volumes:
- /data:/var/lib/mysql
Again for clarification, I cannot simply make the host be localhost because the database I'm using is in a docker and is usually something like 172.17.0.2 or .3 but sometimes it changes. Thank you!