Search code examples
azureubuntudockeripazure-dsvm

How to Route an IP to another IP in Ubuntu?


Here Is my Problem: I Have a Data Science Virtual Machine for Linux (Ubuntu) which going to host my Docker Container. Inside of this container I have a Python script running. I want my C# Client in Azure Cloud integrate with this container. When it request via XMLRPC to call a function of this script via ubuntu ip, my host machine should redirect the ip address to the ip:port/ of the container. Idk how to do this ip redirecting (or maybe is called forwarding/routing?). The easiest solution I found in the internet was XMLRPC. Is anyone able to help me with this also is there any better way instead of XMLRPC or JSONRPC?

this is my client part:

[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);

Solution

  • So if I get this right, you have a C# code running in Azure cloud which is having access to your VM IP.

    I am assuming that your Azure machine is able to reach the IP of your VM. Now when you launch your Python container in the VM, the python server would be listening on some port. Let's assume this port to be 8000. What you need to is that, you need to launch the docker container and publish this port on to the host

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

    Now you have a service which is accessible on your <UbuntuIP>:8000 so you can use that directly in your C# code.