我在使用docker监听microservice上的端口时遇到问题。在本地一切工作都很完美,所以我假设只有正确的配置才有问题。
因此,我开始在特定ip:端口上的microservice上监听snmp消息,方式如下:
private static final String UDP = "udp:/";
private static final String SLASH_PREFIX = "/";
private static final String TRAP_IP = "0.0.0.0"; // or container-name
private void prepareTrapConfiguration() throws IOException {
MessageDispatcher dispatcher = getMessageDispatcher();
Address listenAddress = GenericAddress.parse(String.format("%s%s%s%s", UDP, TRAP_IP, SLASH_PREFIX, 162));
log.debug("Starting listening TRAP on: {} ", listenAddress.toString());
DefaultUdpTransportMapping transport = new DefaultUdpTransportMapping((UdpAddress) listenAddress);
log.info("Started listening TRAP on: {} ", listenAddress.toString());
Snmp snmp = new Snmp(dispatcher, transport);
prepareSecurity(snmp);
snmp.addCommandResponder(trapReceiverCmd);
snmp.listen();
}
private void prepareSecurity(Snmp snmp) {
snmp.getMessageDispatcher().addMessageProcessingModel(new MPv1());
snmp.getMessageDispatcher().addMessageProcessingModel(new MPv2c());
SecurityProtocols.getInstance().addDefaultProtocols();
SecurityProtocols.getInstance().addPrivacyProtocol(new Priv3DES());
}
我开始由docker撰写docker图像。 Docker :
version: '2.1'
services:
snmp:
image: snmp:latest
container_name: snmp
ports:
- "5435:5435"
- "127.0.0.1:162:162/udp"
networks:
- default
restart: always
networks:
default:
driver: bridge
之后,我隧道的ip端口162。我尝试了snmp容器ip,也尝试了使用putty的localhost ip。
最后,我在127.0.0.1:162本地发送了一条消息,但什么也没有发生——它没有在容器上收到。通过wireshark我收到了无法访问的端口
提前谢谢你的小费
1条答案
按热度按时间jvidinwx1#
如果您的主机是windows,请尝试收听
host.docker.internal
,在linux上-172.17.0.1