-
Notifications
You must be signed in to change notification settings - Fork 595
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 'nerdctl container attach' #2108
Conversation
f69e123
to
db9f425
Compare
64efeff
to
4441ce2
Compare
@AkihiroSuda PTAL, thanks! Some jobs seemed to be cancelled for no obvious reason. |
.gitignore
Outdated
@@ -7,3 +7,6 @@ _output | |||
|
|||
# vagrant | |||
/.vagrant | |||
|
|||
# IDE | |||
.vscode |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be in your local git config
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the pointer! TIL 😄
cmd/nerdctl/container_attach.go
Outdated
Args: cobra.ExactArgs(1), | ||
Short: "Attach stdin, stdout, and stderr to a running container.\n\nCaveats:\n\n" + | ||
"- Currently only one attach session is allowed.\n" + | ||
"- Before [dual logging](https://github.com/containerd/nerdctl/issues/1946#issuecomment-1443649307) is implemented, " + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"- Before [dual logging](https://github.com/containerd/nerdctl/issues/1946#issuecomment-1443649307) is implemented, " + | |
"- Until dual logging (issue #1946) is implemented, " + |
) | ||
|
||
// skipAttachForDocker should be called by attach-related tests that assert 'read detach keys' in stdout. | ||
func skipAttachForDocker(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs t.Helper()
func prepareContainerToAttach(base *testutil.Base, containerName string) { | ||
opts := []func(*testutil.Cmd){ | ||
testutil.WithStdin(testutil.NewDelayOnceReader(bytes.NewReader( | ||
[]byte{16, 17}, // https://www.physics.udel.edu/~watson/scen103/ascii.html |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a comment to explain the key codes (C-p C-q)
4441ce2
to
359af70
Compare
@AkihiroSuda All the comments should have been addressed, thanks! |
Sorry needs rebase |
48a17ee
to
9549b3e
Compare
@AkihiroSuda done! |
cmd/nerdctl/container_attach.go
Outdated
Short: "Attach stdin, stdout, and stderr to a running container.\n\nCaveats:\n\n" + | ||
"- Currently only one attach session is allowed.\n" + | ||
"- Until dual logging (issue #1946) is implemented, " + | ||
"a container that is spun up by either `nerdctl run -d` or `nerdctl start` (without `--attach`) cannot be attached to.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use multi-line quote?
`aaa
bbb`
cmd/nerdctl/container_attach.go
Outdated
Use: "attach [flags] CONTAINER", | ||
Args: cobra.ExactArgs(1), | ||
Short: "Attach stdin, stdout, and stderr to a running container.\n\nCaveats:\n\n" + | ||
"- Currently only one attach session is allowed.\n" + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should mention that what happens when the second session tries to attach.
cmd/nerdctl/container_attach.go
Outdated
Short: "Attach stdin, stdout, and stderr to a running container.\n\nCaveats:\n\n" + | ||
"- Currently only one attach session is allowed.\n" + | ||
"- Until dual logging (issue #1946) is implemented, " + | ||
"a container that is spun up by either `nerdctl run -d` or `nerdctl start` (without `--attach`) cannot be attached to.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should list some examples of containers allowed to be attached.
docs/command-reference.md
Outdated
Caveats: | ||
|
||
- Currently only one attach session is allowed. | ||
- Until dual logging (issue #1946) is implemented, a container that is spun up by either `nerdctl run -d` or `nerdctl start` (without `--attach`) cannot be attached to. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we have examples of containers allowed to be attached?
Signed-off-by: Hsing-Yu (David) Chen <davidhsingyuchen@gmail.com>
9549b3e
to
f0140a5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks
Summary
PR is unblocked by #2128. After this PR, for a container started in attached mode, a user can detach from it (enabled by #2128) and then re-attach to it using
nerdctl attach
(enabled by this PR).However, since "dual logging" is not implemented yet, containers spun up in detached mode, namely via
nerdctl run -d
ornerdctl start
(without-a
), cannot benerdctl attach
ed, which is mentioned innerdctl attach --help
andcommand-reference.md
. To be specific, for a container started in detached mode,cio.LogURI
instead ofcio.NewCreator
is used, which means the FIFOs that store the container's stdin/stdout/stderr and will be used bycio.NewAttach
won't be there.Notes
ContainerAttachOptions.GOptions
is not used bycontainer.Attach
at the moment, but I still added it for consistency across commands.docker attach
, only--detach-keys
is supported, and both--no-stdin
andsig-proxy
are not supported yet. We can add support for them in follow-up PRs.cio.Terminal
is not really used bycio.NewAttach
(i.e., whether the container is with a terminal is already decided when the container is created/started), so I omit the logic to decide if it should be passed tocio.NewAttach
.containerd
's current design. Supporting multiple attach sessions at nerdctl side implies quite a bit complexity, so maybe we can leave it to another PR, or even consider doing it at containerd side.