Repository navigation
Conversation
Add nerdctl compose attach, like docker compose attach: it attaches to the container of a service by running nerdctl attach on it. --index selects the container when the service has several instances, and --detach-keys and --no-stdin are passed to nerdctl attach. Like nerdctl attach, it needs a container created with stdin_open and tty. compose up runs such a service in the foreground, like nerdctl run -it, so the test detaches from it with the detach keys. The container lookup is moved from Exec into a serviceContainer helper shared by both commands. Signed-off-by: Srinivas Chippagiri <cvas22@gmail.com>
cvas22
force-pushed
the
feat/compose-attach
branch
from
October 29, 2026 03:22
a0a1908 to
36be14c
Compare
Contributor
Author
|
The failing jobs aren't failing in |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I added
nerdctl compose attach, one more Compose command listed as unimplemented in the command reference (tracked in #3867).It follows
docker compose attach:nerdctl compose attach SERVICEattaches to the service's container by runningnerdctl attachon it, likecompose execrunsnerdctl exec.--indexselects the container when the service has several instances (default 1).--detach-keysand--no-stdinare passed through tonerdctl attach.nerdctl attach, it needs a container created withstdin_open: trueandtty: true. Otherwise the container logs through the logging binary and there is no fifo to attach to.compose upruns such a service in the foreground, likenerdctl run -it, so you detach from it with ctrl-p ctrl-q before attaching. I noted both in the command reference.To avoid duplicating the container lookup, I moved it from
Composer.Execinto aserviceContainerhelper that both commands use. Exec's behavior and error messages are unchanged.Changes:
pkg/composer/attach.go:Composer.Attachpkg/composer/exec.go: the sharedserviceContainerhelpercmd/nerdctl/compose/compose_attach.go: the commandcmd/nerdctl/compose/compose_attach_linux_test.go: tests for an out-of-range index, and for attaching to a service withstdin_openandttythrough a pseudo-TTY (start the project under a pseudo-TTY and detach fromcompose up, then attach, send a command, check its output and detach with ctrl-p ctrl-q), followingTestAttachdocs/command-reference.md: documented the command and removed it from the unimplemented listNotes
I ran the compose integration tests locally, rootful, in a privileged container with nerdctl, containerd, runc, CNI and BuildKit built from this branch (
docker buildx build --target out-full):It passed in three runs in a row. Running the whole
./cmd/nerdctl/compose/package found one problem in an earlier version of this PR, which I fixed: starting the service withrun -ditleaves nothing to attach to (failed to open stdout fifo), so the test now detaches fromcompose upinstead. With that earlier version the other 77 compose tests passed. Rootless is only covered by CI.Like #5300 and #5301, this adds a line to the compose command list, so a trivial rebase may be needed depending on merge order.