如何将一个 IP 路由到 Ubuntu 中的另一个 IP?

How to Route an IP to another IP in Ubuntu?

这是我的问题:我有一个用于 Linux (Ubuntu) 的 Data Science Virtual Machine,它将托管我的 Docker容器。在这个容器中,我有一个 Python 脚本 运行。我希望 Azure Cloud 中的 C# 客户端与此容器集成。当它通过 XMLRPC 请求通过 ubuntu ip 调用此脚本的函数时,我的主机应该将 ip 地址重定向到容器的 ip:port/。 不知道如何做这个 ip 重定向(或者可能叫做 forwarding/routing?)。 我在互联网上找到的最简单的解决方案是 XMLRPC。 有没有人能帮我解决这个问题还有比 XMLRPC 或 JSONRPC 更好的方法吗?

这是我的客户部分:

[XmlRpcUrl("http://@UbuntuIP:666/ContainerIP:8000/RPC2")] 
 public interface ICallServer:IXmlRpcProxy
{
    [XmlRpcMethod]
    string result(string storageAccountName, string containerName,string imageName);
}

ICallServer icallServerTest = XmlRpcProxyGen.Create<ICallServer>();
var output = icallServerTest.func(params);

因此,如果我没看错,你在 Azure 云中有一个 C# 代码 运行,它可以访问你的 VM IP。

我假设您的 Azure 机器能够访问您的 VM 的 IP。现在,当您在 VM 中启动 Python 容器时,python 服务器将侦听某个端口。我们假设此端口为 8000。您需要做的是,您需要启动 docker 容器并将此端口发布到主机

docker run -d --name my-python-container -p 8000:8000 my-python-image

现在您有一个可以在您的 <UbuntuIP>:8000 上访问的服务,因此您可以直接在您的 C# 代码中使用它。