简体   繁体   中英

Server on Azure IOT Edge Linux Ubuntu VM - Want to access the device from outside of the VM

I have a server on a linux vm hosted in an Edge module. I want to access the server on my host machine (Windows), but as far as I'm aware the Edge modules ip address is the localhost of my Linux VM.

How can I change the assignment of the ip address of the Edge modules, so that it takes on the ip address of my linux vm instead of the local host (172...)?

if I understand your question correctly, you want to access a server running inside an Edge module from a different computer. Therefore, the port that the server is listening to has to be exposed on the host, right?

If so, there is a better way than changing the IoT Edge networking. Through 'port mapping', you can take a port exposed from your container/module, and 'map' it such that it gets exposed at the host level, and therefore your other machine can just use the host's IP and your server's port to connect.

For example, let's just say that that the 'server' you are running in your module is web server listening on port 80. If you want to expose that listener on port 80 out to the host, you would do something like this in the "Container Create Options" of your module...

    {
    "PortBindings": {
      "80/tcp": [
        {
          "HostPort": "80"
        }
      ]
    }
  }
}

That will listen for incoming traffic to the host on port 80, and then forward that traffic to your module on port 80. You could even change the 'host port' to something else if you wanted to (eg listen on port 8081 and then 'forward' to port 80 in your module).

One thing to note, if you need to use ports 443, 8883, or 5671, by default those are already mapped by IoT Edge itself. There is a way around that. If you need it, let me know.

Please refer to my question posted in here Azure IoT Edge API module cannot be accessed . For anyone who is struggling to solve such a scenario, you should expose your edge module container running on a guest VM by adding ExposedPorts in createOptions section in deployment.template.json as following. And also IPv4 address of the VM should be used with the relevant port.

        "modules": {
        "test_flask_api": {
        "version": "1.0",
        "type": "docker",
        "status": "running",
        "restartPolicy": "always",
        "settings": {
          "image": "${MODULES.test_flask_api}",
          "createOptions": {
            "ExposedPorts": {
              "5000/tcp": {}
            },
            "HostConfig": {
              "PortBindings": {
                "5000/tcp": [
                  {
                    "HostPort": "5000"
                  }
                ]
              }
            }
          }
        }
      }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM