Skip to content

Conversation

@fhke
Copy link
Contributor

@fhke fhke commented Jan 9, 2022

This PR contains the following updates to the compose up command:

  • Idempotency: rather than failing when a container already exists and has been created by compose, recreate the container. This allows users to iterate rapidly with compose up, rather than deleting & recreating their compose stack to effect changes.
  • Add support for --remove-orphans flag: remove containers for services not defined in the Compose file. This fixes nerdctl compose up support for remove-orphans #342

Signed-off-by: fergal kearns fhke@protonmail.com

return err
}

orphans, err := c.getOrphanContainers(ctx, parsedServices)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This operation might be slow and should be called only when RemoveOrphans is true

Copy link
Contributor Author

@fhke fhke Jan 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @AkihiroSuda, I appreciate this operation could introduce additional delays into the compose up workflow, but without performing it we cannot warn users who have not specified --remove-orphans that orphaned containers exist:

	if numOrphans > 0 {
		if uo.RemoveOrphans {
			if err := c.downContainers(ctx, orphans, true); err != nil {
				return fmt.Errorf("error removing orphaned containers: %s", err)
			}
		} else {
			logrus.Warnf("%d orphaned containers exist. Run with --remove-orphans to remove them.", numOrphans)
		}
	}

This would be a deviation from the behaviour of docker-compose, which prints a similar warning.

We can probably reduce the time taken without losing this error message by comparing the total number of containers in the parsedServices slice with the total number of running containers in the compose project; this would remove the requirement to call the .Labels() method for each container:

	for _, container := range containers {
		containerLabels, err := container.Labels(ctx)
		if err != nil {
			return false, err
		}
		if name == containerLabels[labels.Name] {
			// container exists
			return true, nil
		}
	}

Please let me know if you're happy with that approach, and I'll make the changes accordingly.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be a deviation from the behaviour of docker-compose, which prints a similar warning.

I think this difference is acceptable.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ping @fhke

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @AkihiroSuda, apologies for the delay. I've updated this PR with the requested changes.

@AkihiroSuda AkihiroSuda added this to the v0.16.1 or v0.17.0 milestone Jan 13, 2022
This PR contains the following updates to the `compose up` command:

* Idempotency: rather than failing when a container already exists and has been created by compose, recreate the container. This allows users to iterate rapidly with `compose up`, rather than deleting & recreating their compose stack to effect changes.
* Add support for `--remove-orphans` flag: remove containers for services not defined in the Compose file. This fixes #342

Signed-off-by: fergal kearns <fhke@protonmail.com>
Copy link
Member

@AkihiroSuda AkihiroSuda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@AkihiroSuda AkihiroSuda merged commit 2a198d4 into containerd:master Jan 31, 2022
@AkihiroSuda AkihiroSuda changed the title Enhancements for compose up command. Enhancements for compose up command. (--remove-orphans) Jan 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

nerdctl compose up support for remove-orphans

2 participants