Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

增加Docker部署模式 #380

Merged
merged 1 commit into from
Jan 9, 2020

Conversation

linch90
Copy link
Contributor

@linch90 linch90 commented Jan 8, 2020

服务通过docker集群模式部署时,因有bridge、ingress不同网络,
kestrelserver通过NetUtils随机获取网络时,当只监听ingress网络,此时无法通过bridge访问swagger文档。
增加DockerDeployMode,配置为Swarm模式时,监听0.0.0.0地址。

服务通过docker集群模式部署时,因有bridge、ingress不同网络,
kestrelserver通过NetUtils随机获取网络时,当只监听ingress网络,此时无法通过bridge访问swagger文档。
增加DockerDeployMode,配置为Swarm模式时,监听0.0.0.0地址。
@fanliang11
Copy link
Owner

surging 可以支持0.0.0.0 ,可以配置 surgingSettings.json的 IP,配置如下

{
  "Surging": {
    "Ip": "${Surging_Server_IP}|0.0.0.0",
}
}

@linch90
Copy link
Contributor Author

linch90 commented Jan 9, 2020

这个问题主要是发生在服务器为集群模式下,通过docker stack deploy -c <composefile> <name>命令启动微服务(容器)时,虽然配置文件中“Surging”."Ip"配置成了“0.0.0.0”,但是NetUtils.GetHostAddress -> NetUtils.GetAnyHostAddress方法

public static string GetAnyHostAddress()
        {
            string result = "";
            NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
            foreach (NetworkInterface adapter in nics)
            {
                if (adapter.NetworkInterfaceType == NetworkInterfaceType.Ethernet)
                {
                    IPInterfaceProperties ipxx = adapter.GetIPProperties();
                    UnicastIPAddressInformationCollection ipCollection = ipxx.UnicastAddresses;
                    foreach (UnicastIPAddressInformation ipadd in ipCollection)
                    {
                        if (ipadd.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                        {
                            result = ipadd.Address.ToString();
                        }
                    }
                }
            }
            return result;
        }

中的NetworkInterfaceType.Ethernet类型IP是既有Bridge网络,也有Ingress网络。
所以当返回的是Ingress网络时,就会导致Bridge网络无监听,从而导致容器外部无法通过端口访问Swagger文档。
如果在非集群模式下,正常通过docker-compose up -d这种命令,“Surging”."Ip"配置为“0.0.0.0”,是无任何问题的。

@fanliang11
Copy link
Owner

OK, merge code

@fanliang11 fanliang11 merged commit 6dfd73c into fanliang11:master Jan 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants