@@ -29,6 +29,13 @@ class DockerCollector extends BaseCollector {
2929 this . dockerApi = new DockerAPIClient ( ) ;
3030 }
3131
32+ _normalizeHostIp ( ip ) {
33+ if ( ! ip || ip === '' || ip === '::' || ip === '::0' || ip === '0.0.0.0' ) {
34+ return '0.0.0.0' ;
35+ }
36+ return ip ;
37+ }
38+
3239 async initialize ( ) {
3340 return await this . dockerApi . connect ( ) ;
3441 }
@@ -164,7 +171,8 @@ class DockerCollector extends BaseCollector {
164171
165172 const dockerPorts = await this . _getDockerContainerPorts ( ) ;
166173 dockerPorts . forEach ( ( port ) => {
167- const key = `${ port . host_ip } :${ port . host_port } :${ port . protocol } ` ;
174+ const normalizedIp = this . _normalizeHostIp ( port . host_ip ) ;
175+ const key = `${ normalizedIp } :${ port . host_port } :${ port . protocol } ` ;
168176 if ( ! dockerPortsMap . has ( key ) ) {
169177 if ( port . container_id ) {
170178 port . created = containerCreationTimeMap . get ( port . container_id ) || null ;
@@ -184,8 +192,9 @@ class DockerCollector extends BaseCollector {
184192
185193 if ( container . internalPorts && container . internalPorts . length > 0 ) {
186194 container . internalPorts . forEach ( ( internalPort ) => {
187- const publishedKey = `${ internalPort . host_ip } :${ internalPort . host_port } :${ internalPort . protocol } ` ;
188- const internalKey = `${ internalPort . host_ip } :${ internalPort . host_port } :${ internalPort . protocol } :${ container . id } :internal` ;
195+ const normalizedIp = this . _normalizeHostIp ( internalPort . host_ip ) ;
196+ const publishedKey = `${ normalizedIp } :${ internalPort . host_port } :${ internalPort . protocol } ` ;
197+ const internalKey = `${ normalizedIp } :${ internalPort . host_port } :${ internalPort . protocol } :${ container . id } :internal` ;
189198
190199 if ( ! dockerPortsMap . has ( publishedKey ) && ! dockerPortsMap . has ( internalKey ) ) {
191200 internalPort . created = containerCreationTimeMap . get ( container . id ) || null ;
@@ -203,7 +212,9 @@ class DockerCollector extends BaseCollector {
203212 const systemPorts = await this . _getSystemPorts ( ) ;
204213
205214 for ( const port of systemPorts ) {
206- const key = `${ port . host_ip } :${ port . host_port } ` ;
215+ // Use same key format as docker ports for proper dedup
216+ const normalizedIp = this . _normalizeHostIp ( port . host_ip ) ;
217+ const key = `${ normalizedIp } :${ port . host_port } :${ port . protocol || 'tcp' } ` ;
207218 if ( dockerPortsMap . has ( key ) ) {
208219 continue ;
209220 }
@@ -301,10 +312,10 @@ class DockerCollector extends BaseCollector {
301312 const targetPort = parseInt ( port , 10 ) ;
302313
303314 for ( const binding of hostBindings ) {
304- const hostIp = binding . HostIp || '0.0.0.0' ;
315+ const hostIp = this . _normalizeHostIp ( binding . HostIp ) ;
305316 const hostPort = parseInt ( binding . HostPort , 10 ) ;
306317
307- if ( ! hostIp || isNaN ( hostPort ) ) continue ;
318+ if ( isNaN ( hostPort ) ) continue ;
308319
309320 portEntries . push (
310321 this . normalizePortEntry ( {
0 commit comments