Skip to content

Commit 38507f9

Browse files
committed
chore: improve the visibility of orphaned containers in logs
When executing the command on a compose file like the one below, orphaned containers are displayed, but the current implementation does not show the IDs of these orphaned containers, making them difficult to identify. ``` $ cat compose-full.yaml services: test: image: docker.io/library/busybox:latest command: ["sleep", "infinity"] orphan: image: docker.io/library/busybox:latest command: ["sleep", "infinity"] $ cat compose-orphan.yaml services: test: image: docker.io/library/busybox:latest command: ["sleep", "infinity"] $ sudo nerdctl compose -f compose-full.yaml up -d ... $ sudo nerdctl compose -f compose-orphan.yaml down -v ... WARN[0010] found 1 orphaned containers: [0x4000340000], you can run this command with the --remove-orphans flag to clean it up ... ``` Therefore, this commit modifies to display the IDs of orphaned containers. Additionally, since there was other logic that performed similar displays, this commit also modifies it in the same manner. Signed-off-by: Hayato Kiwata <haytok@amazon.co.jp>
1 parent 7d79937 commit 38507f9

File tree

4 files changed

+11
-3
lines changed

4 files changed

+11
-3
lines changed

pkg/composer/down.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func (c *Composer) Down(ctx context.Context, downOptions DownOptions) error {
6565
return fmt.Errorf("error removeing orphaned containers: %w", err)
6666
}
6767
} else {
68-
log.G(ctx).Warnf("found %d orphaned containers: %v, you can run this command with the --remove-orphans flag to clean it up", len(orphans), orphans)
68+
log.G(ctx).Warnf("found %d orphaned containers: %v, you can run this command with the --remove-orphans flag to clean it up", len(orphans), containerShortIDs(orphans))
6969
}
7070
}
7171

pkg/composer/orphans.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,11 @@ func (c *Composer) getOrphanContainers(ctx context.Context, parsedServices []*se
5555

5656
return orphanContainers, nil
5757
}
58+
59+
func containerShortIDs(containers []containerd.Container) []string {
60+
names := make([]string, 0, len(containers))
61+
for _, c := range containers {
62+
names = append(names, c.ID()[:12])
63+
}
64+
return names
65+
}

pkg/composer/run.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ func (c *Composer) Run(ctx context.Context, ro RunOptions) error {
201201
return fmt.Errorf("error removing orphaned containers: %w", err)
202202
}
203203
} else {
204-
log.G(ctx).Warnf("found %d orphaned containers: %v, you can run this command with the --remove-orphans flag to clean it up", len(orphans), orphans)
204+
log.G(ctx).Warnf("found %d orphaned containers: %v, you can run this command with the --remove-orphans flag to clean it up", len(orphans), containerShortIDs(orphans))
205205
}
206206
}
207207

pkg/composer/up.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ func (c *Composer) Up(ctx context.Context, uo UpOptions, services []string) erro
116116
return fmt.Errorf("error removing orphaned containers: %w", err)
117117
}
118118
} else {
119-
log.G(ctx).Warnf("found %d orphaned containers: %v, you can run this command with the --remove-orphans flag to clean it up", len(orphans), orphans)
119+
log.G(ctx).Warnf("found %d orphaned containers: %v, you can run this command with the --remove-orphans flag to clean it up", len(orphans), containerShortIDs(orphans))
120120
}
121121
}
122122

0 commit comments

Comments
 (0)