Skip to content

Commit 3a2638c

Browse files
committed
dockerdiscovery: use Compose project name for service name (which might be used for ACL)
this is to provide more stable identifiers so if we use ACL rules the identifiers don't change all the time. (for example Docker's newer Go-based Compose generation changed how the container names are formatted)
1 parent e7593fd commit 3a2638c

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

pkg/erdiscovery/dockerdiscovery/docker.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,11 +296,22 @@ func discoverDockerContainers(
296296
continue
297297
}
298298

299+
// service name is kind of important as it might be used in different kinds of identifiers.
300+
// maybe in ACLs, to query logs etc.
301+
//
302+
// let's try to use the most stable thing. the container name is not great, as Compose laid the names like:
303+
// - /calendarserver_baikal_1
304+
// then they arbitrarily changed it from underscores to dashes:
305+
// - /calendarserver-baikal-1
306+
//
307+
// so looks like the compose project name is more stable and reliable, only after that prefer the container name.
308+
//
299309
// use swarm service name if defined, so we get stable names ("baikal_baikal") instead of
300310
// "/baikal_baikal.1.mifsjkoi93gwh9yg89c51va0t" for Swarm-based containers. normally we don't
301-
// use this discoverDockerContainers() but Swarm, but if we use docker_gwbridge this is how
311+
// use this discoverDockerContainers() for Swarm, but if we use docker_gwbridge this is how
302312
// we discover conainers outside of Swarm network contexts
303313
serviceName := coalesce(
314+
container.Labels["com.docker.compose.project"],
304315
container.Labels["com.docker.swarm.service.name"],
305316
container.Names[0])
306317

0 commit comments

Comments
 (0)