@@ -108,6 +108,11 @@ func (c *container) PID() int {
108
108
109
109
func (c * container ) Hostname () string {
110
110
if c .container .Config .Domainname == "" {
111
+ // If hostname isn't set on a container it defaults to a random hex
112
+ // number which we don't want to show in the UI.
113
+ if strings .HasPrefix (c .container .ID , c .container .Config .Hostname ) {
114
+ return ""
115
+ }
111
116
return c .container .Config .Hostname
112
117
}
113
118
@@ -375,13 +380,16 @@ func (c *container) getSanitizedCommand() string {
375
380
}
376
381
377
382
func (c * container ) getBaseNode () report.Node {
378
- result := report .MakeNodeWith (report .MakeContainerNodeID (c .ID ()), map [string ]string {
379
- ContainerID : c .ID (),
380
- ContainerCreated : c .container .Created .Format (time .RFC3339Nano ),
381
- ContainerCommand : c .getSanitizedCommand (),
382
- ImageID : c .Image (),
383
- ContainerHostname : c .Hostname (),
384
- }).WithParent (report .ContainerImage , report .MakeContainerImageNodeID (c .Image ()))
383
+ properties := map [string ]string {
384
+ ContainerID : c .ID (),
385
+ ContainerCreated : c .container .Created .Format (time .RFC3339Nano ),
386
+ ContainerCommand : c .getSanitizedCommand (),
387
+ ImageID : c .Image (),
388
+ }
389
+ if hostname := c .Hostname (); hostname != "" {
390
+ properties [ContainerHostname ] = hostname
391
+ }
392
+ result := report .MakeNodeWith (report .MakeContainerNodeID (c .ID ()), properties ).WithParent (report .ContainerImage , report .MakeContainerImageNodeID (c .Image ()))
385
393
result = result .AddPrefixPropertyList (LabelPrefix , c .container .Config .Labels )
386
394
if ! c .noEnvironmentVariables {
387
395
result = result .AddPrefixPropertyList (EnvPrefix , c .env ())
0 commit comments