From 7f975fa40bd5f5b65c17d2275aeb27712c503501 Mon Sep 17 00:00:00 2001 From: i-ky Date: Thu, 1 Dec 2022 17:48:13 +0200 Subject: [PATCH] Fix replacing "service:x" with "container:y" Signed-off-by: i-ky --- pkg/compose/convergence.go | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/pkg/compose/convergence.go b/pkg/compose/convergence.go index d81d40dda..1c92eaea1 100644 --- a/pkg/compose/convergence.go +++ b/pkg/compose/convergence.go @@ -126,17 +126,22 @@ func updateServices(service *types.ServiceConfig, cnts Containers) { if len(cnts) == 0 { return } - cnt := cnts[0] - serviceName := cnt.Labels[api.ServiceLabel] + serviceName2containerID := make(map[string]string) + for _, cnt := range cnts { + serviceName := cnt.Labels[api.ServiceLabel] + if _, exists := serviceName2containerID[serviceName]; !exists { + serviceName2containerID[serviceName] = cnt.ID + } + } - if d := getDependentServiceFromMode(service.NetworkMode); d == serviceName { - service.NetworkMode = types.NetworkModeContainerPrefix + cnt.ID + if id, found := serviceName2containerID[getDependentServiceFromMode(service.NetworkMode)]; found { + service.NetworkMode = types.NetworkModeContainerPrefix + id } - if d := getDependentServiceFromMode(service.Ipc); d == serviceName { - service.Ipc = types.NetworkModeContainerPrefix + cnt.ID + if id, found := serviceName2containerID[getDependentServiceFromMode(service.Ipc)]; found { + service.Ipc = types.NetworkModeContainerPrefix + id } - if d := getDependentServiceFromMode(service.Pid); d == serviceName { - service.Pid = types.NetworkModeContainerPrefix + cnt.ID + if id, found := serviceName2containerID[getDependentServiceFromMode(service.Pid)]; found { + service.Pid = types.NetworkModeContainerPrefix + id } var links []string for _, serviceLink := range service.Links {