I am developing ASP.NET Core Web Server + MySQL + Redis on Docker.
My web server should be connected to both MySQL and Redis, and I set these connection info in appsettings.json.
While it runs on Windows host, the ip addresses of both containers under a docker network are like this.
> docker network inspect test_net
{
...
"Containers": {
"***": {
"Name": "mysql",
"IPv4Address": "172.18.0.3/16"
},
"***": {
"Name": "redis",
"IPv4Address": "172.18.0.2/16"
},
...
}
}
So I set "ConnectionStrings" like below,
"ConnectionStrings": {
"mysql": "server=172.18.0.3;user=root;password=**;port=3306;database=Test;",
"redis": "172.18.0.2:6379,abortConnect=false"
}
But when it runs on CentOS host, the ip addresses of them are opposite to each other. This occurs connection errors.
> docker network inspect test_net
{
...
"Containers": {
"***": {
"Name": "redis",
"IPv4Address": "172.18.0.3/16"
},
"***": {
"Name": "mysql",
"IPv4Address": "172.18.0.2/16"
},
...
}
}
How can I make it always run in the same environment?