Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add detachKeys option to container start #159

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

coderbirju
Copy link
Contributor

Issue #, if available:

Description of changes:

Testing done:

  • I've reviewed the guidance in CONTRIBUTING.md

License Acceptance

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@coderbirju coderbirju force-pushed the update-start-options branch 2 times, most recently from 5f4ffdd to 27061be Compare February 18, 2025 21:46
@coderbirju coderbirju marked this pull request as ready for review February 18, 2025 21:55
"github.com/runfinch/finch-daemon/pkg/errdefs"
)

func (s *service) Restart(ctx context.Context, cid string, timeout time.Duration) error {
con, err := s.getContainer(ctx, cid)
func (s *service) Restart(ctx context.Context, containers []string, options types.ContainerRestartOptions) error {
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need to change from taking cid string to containers []string?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nerdctl currentl accepts container id's in []string format.
I think making our functions take cid in input was the right approach, we can send the cid in the format that nerdctl expects when we make that call.

Starting multiple containers is not a feature that docker supports at the moment - https://docs.docker.com/reference/api/engine/version/v1.43/#tag/Container/operation/ContainerStart

I will update this.

Copy link
Member

Choose a reason for hiding this comment

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

Sounds good, thanks

@@ -22,9 +22,9 @@ type Service interface {
GetPathToFilesInContainer(ctx context.Context, cid string, path string) (string, func(), error)
Remove(ctx context.Context, cid string, force, removeVolumes bool) error
Wait(ctx context.Context, cid string, condition string) (code int64, err error)
Start(ctx context.Context, cid string) error
Start(ctx context.Context, containers []string, options ncTypes.ContainerStartOptions) error
Copy link
Contributor

Choose a reason for hiding this comment

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

Does docker api support starting multiple containers?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pasting from another thread

Nerdctl currentl accepts container id's in []string format.
I think making our functions take cid in input was the right approach, we can send the cid in the format that nerdctl expects when we make that call.

Starting multiple containers is not a feature that docker supports at the moment - https://docs.docker.com/reference/api/engine/version/v1.43/#tag/Container/operation/ContainerStart

I will update this.

Stop(ctx context.Context, cid string, timeout *time.Duration) error
Restart(ctx context.Context, cid string, timeout time.Duration) error
Restart(ctx context.Context, containers []string, options ncTypes.ContainerRestartOptions) error
Copy link
Contributor

Choose a reason for hiding this comment

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

Same

ctx := namespaces.WithNamespace(r.Context(), h.Config.Namespace)
err = h.service.Restart(ctx, cid, timeout)
containers := [1]string{cid}
Copy link
Contributor

Choose a reason for hiding this comment

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

May just pass cid directly, if we are not planning to support multiple containers

err = h.service.Restart(ctx, cid, timeout)
containers := [1]string{cid}
globalOpt := ncTypes.GlobalCommandOptions(*h.Config)
options := ncTypes.ContainerRestartOptions{
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nerdctl doesn't yet have signal option in restart, I have a WIP PR for that
https://github.com/coderbirju/nerdctl/pull/12/files

@@ -17,7 +19,26 @@ import (
func (h *handler) start(w http.ResponseWriter, r *http.Request) {
cid := mux.Vars(r)["id"]
ctx := namespaces.WithNamespace(r.Context(), h.Config.Namespace)
err := h.service.Start(ctx, cid)

detachKeys := r.URL.Query().Get("detachKeys")
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add some validation for possible detachkeys values?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

According to this documentation user can provide an arbitrary sequence of their choice to detached from the container - https://docs.docker.com/reference/cli/docker/container/attach/#detach-keys

I can add some sort of validation to check if the sequence they've provided is in the appropriate format

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added validation

options := ncTypes.ContainerStartOptions{
GOptions: globalOpt,
Stdout: devNull,
Attach: false,
Copy link
Contributor

Choose a reason for hiding this comment

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

nerdctl start supports attach https://github.com/containerd/nerdctl/blob/main/docs/command-reference.md#whale-nerdctl-start. Can we pass it, instead of setting this to False by default.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would that be an additional option in container start API?
Docker doesn't support it at the moment - https://docs.docker.com/reference/api/engine/version/v1.43/#tag/Container/operation/ContainerStart

Copy link
Contributor

Choose a reason for hiding this comment

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

I see. Looks like docker-cli makes a separate ContainerAttach call for that https://github.com/docker/cli/blob/master/cli/command/container/start.go#L113.

The current implementation looks good to me, but we should follow up later on the end to end Start with attach behavior

Signed-off-by: Arjun Raja Yogidas <arjunry@amazon.com>
pendo324
pendo324 previously approved these changes Feb 19, 2025
Signed-off-by: Arjun Raja Yogidas <arjunry@amazon.com>
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.

3 participants