Support NewTerminal & Detached mode (nerdctl -t -d)#1642
Conversation
|
Thanks, but how to test? |
This requires building a container that only works properly with -t -d (or -t) modes |
f907bf5 to
5438991
Compare
|
@AkihiroSuda PTAL |
1df53f0 to
af918c0
Compare
|
@fahedouch @djdongjin PTAL |
| if runtime.GOOS == "windows" { | ||
| t.Skip("buildkit is not enabled on windows, this feature may work on windows.") | ||
| } | ||
| testutil.DockerIncompatible(t) |
There was a problem hiding this comment.
Why incompatible?
using -d will use the json-file log driver and cause the windows test fail
|
|
||
| // this container only works properly with -t -d (or -t) modes | ||
| const TerminalContainerDockerfile = ` | ||
| FROM golang:latest as builder |
There was a problem hiding this comment.
Please pin the golang version and go.sum.
Also, can we avoid using golang here?
There was a problem hiding this comment.
Please pin the golang version and go.sum.
Also, can we avoid using golang here?
We can package the container in advance and just provide the image name, what do you think?
There was a problem hiding this comment.
I'd prefer to minimize dependency on third party images unless it is unavoidable
There was a problem hiding this comment.
I thought of an easier way, just run the container directly (bash or /bin/sh), this requires -t to run properly,
no need to build image anymore
|
|
| } | ||
| return nil | ||
| }) | ||
| base.Cmd("container", "rm", "-f", containerName).AssertOK() |
There was a problem hiding this comment.
This line can be a defer and moved up to before or after line 506, so that the rm -f containerName is always called.
Right now if either 507 or 517 fails, the container won't be cleaned.
There was a problem hiding this comment.
Here are actually two little tests, with "-t" and without "-t", so the container must be deleted before running again.
Perhaps use different name? or test separately?
There was a problem hiding this comment.
I think you can use different names and defer both rm -f containerName calls.
Same for the test in cmd/nerdctl/create_linux_test.go
There was a problem hiding this comment.
I think you can use different names and
deferbothrm -f containerNamecalls.Same for the test in cmd/nerdctl/create_linux_test.go
Great, thanks
333e9ed to
e0ef207
Compare
| assert.Check(t, strings.Contains(log, "bar")) | ||
| } | ||
|
|
||
| func TestNewTerminalDetachedMode(t *testing.T) { |
There was a problem hiding this comment.
This test failed on windows. Not sure if it's due to some issue or not supported on windows.
Also suggest to include Run in the func name, something like TestRunWithTtyAndDetached.
There was a problem hiding this comment.
This test failed on windows. Not sure if it's due to some issue or not supported on windows.
it seems that the error location is different every time
There was a problem hiding this comment.
This test failed on windows. Not sure if it's due to some issue or not supported on windows.
using -d will use the json-file log driver and cause the windows test fail
5099881 to
61e4f19
Compare
61e4f19 to
09b37d5
Compare
| defer base.Cmd("container", "rm", "-f", withTerminalContainerName).AssertOK() | ||
| withTerminalContainer := base.InspectContainer(withTerminalContainerName) | ||
| assert.Equal(base.T, "running", withTerminalContainer.State.Status) | ||
| assert.Equal(base.T, true, withTerminalContainer.State.Running) |
There was a problem hiding this comment.
The test has to verify that tty is allocated when -t is specified.
Probably you can just test stty
$ docker run -d --name without-t alpine stty
f6ee65e70c512ddba7846f595f3dc5ce0cdb72110e9f901d1661e05f0a8a1372
$ docker logs without-t
stty: standard input: Not a tty
$ docker container inspect without-t | jq .[0].State.ExitCode
1$ docker run -td --name with-t alpine stty
5b7bf5c0b3b07af1ccbe2c049aa34841ea635e10c0b493e056201e16dd38de03
$ docker logs with-t
speed 38400 baud; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V; flush = ^O; min = 1; time = 0;
-brkint -imaxbel
$ docker container inspect with-t | jq .[0].State.ExitCode
0There was a problem hiding this comment.
The test has to verify that tty is allocated when
-tis specified.Probably you can just test
stty$ docker run -d --name without-t alpine stty f6ee65e70c512ddba7846f595f3dc5ce0cdb72110e9f901d1661e05f0a8a1372 $ docker logs without-t stty: standard input: Not a tty $ docker container inspect without-t | jq .[0].State.ExitCode 1$ docker run -td --name with-t alpine stty 5b7bf5c0b3b07af1ccbe2c049aa34841ea635e10c0b493e056201e16dd38de03 $ docker logs with-t speed 38400 baud; line = 0; intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V; flush = ^O; min = 1; time = 0; -brkint -imaxbel $ docker container inspect with-t | jq .[0].State.ExitCode 0
done
Signed-off-by: yaozhenxiu <946666800@qq.com>
e45ce4d to
c67b102
Compare
1 support run
-t -dnerdctal run --name demo -t -d imagename
2 support create
-tnerdctl create --name demo -t imagename
nerdctl start demo
3 support start
-ato attach a terminal containernerdctl create --name demo -t imagename
nerdctl start -a demo
4 support start/restart the container that run with
-it(or without-d)nerdctl run --name demo -it imagename
ctrl + cto stop demonerdctl start/restart demo
Signed-off-by: yaozhenxiu 946666800@qq.com