feat(run): allow -i and -d together when -t is set#4989
Conversation
Local test resultsRun in a Linux + containerd dev sandbox (Docker Environment
Static checks
New tests — Regression — existing attach suite Manual flag matrix also verified: |
Manually verified flag matrix
|
2e71957 to
14d4e2c
Compare
There was a problem hiding this comment.
Pull request overview
This PR updates nerdctl run/create flag validation to allow -i (interactive) and -d (detach) to be used together only when -t (TTY) is also set, addressing Issue #317 by removing the previous hardcoded FIXME rejection and replacing it with a clearer, behavior-based constraint.
Changes:
- Allow
-i -dwhen-tis enabled (TTY case). - Reject non-TTY
-i -dwith a clear error message explaining the constraint. - Add Linux integration tests covering both the allowed (
-t -d -i) and rejected (-d -iwithout-t) cases.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
pkg/cmd/container/create.go |
Replaces the old FIXME hard-fail with a conditional validation that only rejects -i -d when -t is not set, and improves the error message. |
cmd/nerdctl/container/container_run_detach_interactive_linux_test.go |
Adds integration tests to ensure run -t -d -i works and run -d -i fails with the expected error. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Please squash the commits |
981c55e to
c413000
Compare
Previously `nerdctl run` rejected -i with -d unconditionally via a FIXME error. The combination is valid when -t is also given: the containerd shim holds the pty open, so the detached container keeps a usable stdin. Without -t, a detached interactive container cannot work in nerdctl's daemonless model -- there is no persistent process to hold the container's stdin open, so the process would read EOF immediately. That case now returns a clear error instead of the FIXME. Add integration tests for the accepted (-t -d -i) and rejected (-d -i) cases. Signed-off-by: Mayur Das <mayur.das@neevcloud.com>
c413000 to
4213f61
Compare
Fixes #317
nerdctl runrejected-itogether with-dvia a hardcoded FIXME, so the command in #317 (nerdctl run -t -d -i ...) failed.What this does
-i -dwhen-tis also set — with a TTY the containerd shim holds the pty open, so the detached container keeps a usable stdin and stays running. Unblocks the issue's exact command.-t, returns a clear error (flags -i and -d can only be specified together with -t) instead of the FIXME.Why not non-TTY
-d -i?nerdctl is daemonless. For a detached container, stdout/stderr use containerd binary logging; the shim's
createIOpicks the IO path solely from the stdout URI scheme, so abinary://logger and a stdin FIFO can't coexist. With no daemon to hold a plain stdin pipe open, a non-TTY-d -iprocess reads EOF immediately. Docker supports it only because dockerd holds the FIFOs; doing so in nerdctl would need a persistent per-container IO holder (conmon-style), out of scope here.Out of scope
run/createonly — the same FIXME inexec/compose runis left alone.TerminalBinaryIOstores abinary://stdout thatattachcan't reopen).Tests
New
cmd/nerdctl/container/container_run_detach_interactive_linux_test.go:TestRunDetachInteractiveWithTTY—run -t -d -iruns detached and stays running.TestRunDetachInteractiveWithoutTTYFails—run -d -i(no -t) fails with the clear error (nerdctl-only; Docker supports it).Verified locally in a Linux + containerd sandbox: gofmt, go vet, build, and the new + existing
TestAttach*integration tests pass.cc @AkihiroSuda