如果在docker-compose中使用network_mode: host
调出容器,则程序将正常执行。但是,在不将容器映射到主机网络的情况下,我无法弄清楚如何绑定到套接字...
有什么主意吗?
我的docker-compose.yml:
version: '3.6'
services:
container-one:
command: ['npm', 'start']
image: 'ccontainer-one:${VERSION}'
build:
context: ./containers/container-one
restart: always
networks:
- consumer
ports:
- '55014:55014/udp'
networks:
consumer:
driver: bridge
这总是失败:
const dgram = require('dgram')
const socket = dgram.createSocket('udp4')
socket.bind(55014, () => {
try {
return socket.addMembership(229.1.80.20, 10.10.5.1)
} catch (e) {
throw new Error(`is interface up? can't bind to 229.1.80.20:55014 from 10.10.5.1`)
}