Adapter-Agent not Resolving Hostnames inside a Docker Container
Description
When using the adapter-agent feature on v2.0 the hostname of a container does not seem to resolve. Researching online solutions shows that the codebase may need to be updated in order to resolve the host names from within a linux container. Could you please help to validate this bug/feature?
Agent 2.0 Setup (using agent-adapter)
Agent.cfg
...
Adapters {
# Log file has all machines with device name prefixed
device {
Url = http://testdevice:5005
SourceDevice = device
}
}
...
Device.xml
<?xml version="1.0" encoding="UTF-8"?>
<MTConnectDevices xmlns:m="urn:mtconnect.org:MTConnectDevices:1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:mtconnect.org:MTConnectDevices:1.1" xsi:schemaLocation="urn:mtconnect.org:MTConnectDevices:1.1 http://www.mtconnect.org/schemas/MTConnectDevices_1.1.xsd">
<Header creationTime="2009-03-22T01:50:29+00:00" sender="localhost" instanceId="1237628993" bufferSize="100000" version="1.0"/>
<Devices>
<Device iso841Class="6" uuid="unique-device-id-updated" name="device" sampleInterval="2000.0" id="d">
...
Test Device (Agent 1.x)
Agent 1.x agent.cfg :
...
Adapters {
# Log file has all machines with device name prefixed
device {
Host = adapter
Port = 7878
}
}
...
Device.xml
<?xml version="1.0" encoding="UTF-8"?>
<MTConnectDevices xmlns:m="urn:mtconnect.org:MTConnectDevices:1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:mtconnect.org:MTConnectDevices:1.1" xsi:schemaLocation="urn:mtconnect.org:MTConnectDevices:1.1 http://www.mtconnect.org/schemas/MTConnectDevices_1.1.xsd">
<Header creationTime="2009-03-22T01:50:29+00:00" sender="localhost" instanceId="1237628993" bufferSize="100000" version="1.0"/>
<Devices>
<Device iso841Class="6" uuid="unique-device-id" name="device" sampleInterval="2000.0" id="d">
...
Dockerization
The test device and the agent are both created with dockerfiles to spin up containers for each. The linked network allows for communication between the containers.
Docker-compose.yaml
version: "3.9"
services:
agent:
build: ./agent
network_mode: "host"
ports:
- "5001:5000"
testdevice:
build: ./adapter/tests/test_device
ports:
- "5005:5000"
Logs from Agent 2.0
Notice that the host is not resolved http://testdevice:5005/device in the following log output.
MTConnect Agent Version 2.0.0.8 - built on Sat Jun 4 13:20:28 2022
[2022-07-06 15:32:53.874046] [0x00007fe80f89e780] [info] Loading configuration from: "/MTC_Agent/agent.cfg"
2022-07-06T15:32:53.875481Z (0x00007fe80f89e780) [info] MAIN->AgentConfiguration::initialize->AgentConfiguration::loadConfig: Starting agent on port 5000
2022-07-06T15:32:53.934755Z (0x00007fe80f89e780) [warning] MAIN->AgentConfiguration::initialize->AgentConfiguration::loadConfig->AgentConfiguration::loadSinks: The following path "./styles/old" is not a regular file: "/MTC_Agent/./styles/old"
2022-07-06T15:32:53.953756Z (0x00007fe80f89e780) [info] MAIN->AgentConfiguration::initialize->AgentConfiguration::loadConfig->AgentConfiguration::loadAdapters: http: Adding adapter for device: device
2022-07-06T15:32:53.968986Z (0x00007fe80ee9b640) [error] : Cannot resolve address testdevice, shutting down
2022-07-06T15:32:53.969038Z (0x00007fe80ee9b640) [error] : Reason: asio.netdb Host not found (authoritative)
2022-07-06T15:32:53.969065Z (0x00007fe80ee9b640) [error] : resolve: Adapter failed and cannot recover
2022-07-06T15:32:53.969133Z (0x00007fe80ee9b640) [debug] : Disconnected from adapter, setting all values to UNAVAILABLE
2022-07-06T15:32:53.969202Z (0x00007fe80ee9b640) [fatal] : Source http://testdevice:5005/device failed
2022-07-06T15:32:53.969213Z (0x00007fe80ee9b640) [fatal] : No external adapters present, shutting down
To validate the url is available an attached shell to the testdevice container allows us to run the localhost:5000/device curl command and validate the xml output. A browser on the host computer was also able to reach the http://testdevice:5005 address.
Validating host is reachable
On host browser :

On testdevice container:

Possible resolutions :
- The resolution of the host name requires changes to the c++ codebase according to the following links : https://gitlab.com/eidheim/Simple-Web-Server/-/issues/281
I'll check this out and put together a fix.
version: "3.9"
services:
agent:
build: ./agent
network_mode: "host"
ports:
- "5001:5000"
testdevice:
build: ./adapter/tests/test_device
ports:
- "5005:5000"
I wouldn't expect agent in host mode to resolve default bridge network hostnames. Why is the agent sharing network with host?
Agree. It is using standard name resolution. We may need to find a workaround. BestW(Sent from mobile)On Oct 3, 2022, at 07:02, MRIIOT @.***> wrote: version: "3.9" services: agent: build: ./agent network_mode: "host" ports: - "5001:5000" testdevice: build: ./adapter/tests/test_device ports: - "5005:5000" ```
I wouldn't expect agent in host mode to resolve default bridge network hostnames.
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you commented.Message ID: @.***>
If testdevice is an agent and keeping compose file the same:
Adapters {
# Log file has all machines with device name prefixed
device {
Url = http://localhost:5005
SourceDevice = device
}
}
If agent can move to same network as testdevice:
Adapters {
# Log file has all machines with device name prefixed
device {
Url = http://testdevice:5000
SourceDevice = device
}
}
I believe this has been resolved. Please get back if it is still an issue.
I’m going to close this as it has been addressed