Skip to content

Commit e832586

Browse files
authored
Merge pull request #4372 from apostasie/2025-06-compose-exec-unlock
Allow compose exec concurrency
2 parents b25edf5 + b6ceafb commit e832586

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

cmd/nerdctl/compose/compose_exec_linux_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,11 @@ services:
279279
data.Labels().Set("projectName", strings.ToLower(filepath.Base(data.Temp().Dir())))
280280

281281
helpers.Ensure("compose", "-f", yamlPath, "up", "-d", "svc0")
282+
283+
// Make sure all containers are started so that /etc/hosts is consistent.
284+
for _, index := range []string{"1", "2", "3"} {
285+
nerdtest.EnsureContainerStarted(helpers, fmt.Sprintf("%s-svc0-%s", data.Labels().Get("projectName"), index))
286+
}
282287
}
283288

284289
testCase.Cleanup = func(data test.Data, helpers test.Helpers) {

pkg/composer/exec.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ type ExecOptions struct {
4949
// Exec executes a given command on a running container specified by
5050
// `ServiceName` (and `Index` if it has multiple instances).
5151
func (c *Composer) Exec(ctx context.Context, eo ExecOptions) error {
52+
// Exec does not need to lock and should allow concurrency.
53+
if err := Unlock(); err != nil {
54+
return err
55+
}
56+
5257
containers, err := c.Containers(ctx, eo.ServiceName)
5358
if err != nil {
5459
return fmt.Errorf("fail to get containers for service %s: %w", eo.ServiceName, err)

0 commit comments

Comments
 (0)