From b9bf469695c2a5a34084dac0406a61c0eb15c361 Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Sun, 23 Jun 2019 21:15:49 +1000 Subject: [PATCH] use one-off label to determine whether a container is bound to a service --- pkg/commands/container.go | 4 +++- pkg/commands/docker.go | 7 ++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/pkg/commands/container.go b/pkg/commands/container.go index 855657f6..0d55921e 100644 --- a/pkg/commands/container.go +++ b/pkg/commands/container.go @@ -22,8 +22,10 @@ import ( type Container struct { Name string ServiceName string - ServiceID string ContainerNumber string // might make this an int in the future if need be + + // OneOff tells us if the container is just a job container or is actually bound to the service + OneOff bool ProjectName string ID string Container types.Container diff --git a/pkg/commands/docker.go b/pkg/commands/docker.go index 5f470c71..33e0bdee 100644 --- a/pkg/commands/docker.go +++ b/pkg/commands/docker.go @@ -244,7 +244,7 @@ func (c *DockerCommand) assignContainersToServices(containers []*Container, serv L: for _, service := range services { for _, container := range containers { - if container.ServiceID != "" && container.ServiceID == service.ID { + if !container.OneOff && container.ServiceName == service.Name { service.Container = container continue L } @@ -253,12 +253,13 @@ L: } } +// obtainStandaloneContainers returns standalone containers. Standalone containers are containers which are either one-off containers, or whose service is not part of this docker-compose context func (c *DockerCommand) obtainStandaloneContainers(containers []*Container, services []*Service) []*Container { standaloneContainers := []*Container{} L: for _, container := range containers { for _, service := range services { - if container.ServiceID != "" && container.ServiceID == service.ID { + if !container.OneOff && container.ServiceName != "" && container.ServiceName == service.Name { continue L } } @@ -313,9 +314,9 @@ func (c *DockerCommand) GetContainers() ([]*Container, error) { newContainer.Name = strings.TrimLeft(container.Names[0], "/") } newContainer.ServiceName = container.Labels["com.docker.compose.service"] - newContainer.ServiceID = container.Labels["com.docker.compose.config-hash"] newContainer.ProjectName = container.Labels["com.docker.compose.project"] newContainer.ContainerNumber = container.Labels["com.docker.compose.container"] + newContainer.OneOff = container.Labels["com.docker.compose.oneoff"] == "True" ownContainers[i] = newContainer }