0

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?

Ellisein
  • 650
  • 3
  • 12
  • is your core app running in a container as well? Then you should use docker networking/dns. Generally, those IPs are randomly assigned. You can make it static with flags, See https://stackoverflow.com/questions/27937185/assign-static-ip-to-docker-container#35359185 – The Fool Apr 14 '22 at 08:11

0 Answers0