containerd / nerdctl

contaiNERD CTL - Docker-compatible CLI for containerd, with support for Compose, Rootless, eStargz, OCIcrypt, IPFS, ...
Apache License 2.0
8.24k stars 614 forks source link

panic: provided file is not a console #3297

Closed apostasie closed 3 months ago

apostasie commented 3 months ago

Description

Likely while mistakenly starting a container with -ti on the CI.

We probably want to do better than a panic.

panic: provided file is not a console
goroutine 1 [running]:
github.com/containerd/console.Current()
    /home/runner/go/pkg/mod/github.com/containerd/console@v1.0.4/console.go:80 +0x94
github.com/containerd/nerdctl/v2/pkg/cmd/container.generateExecProcessSpec({_, _}, _, {_, _}, {_, _, _}, {{0x0, 0x0, ...}, ...})
    /home/runner/work/nerdctl/nerdctl/pkg/cmd/container/exec.go:167 +0x3ee
github.com/containerd/nerdctl/v2/pkg/cmd/container.execActionWithContainer({_, _}, _, {_, _}, {_, _, _}, {{0x0, 0x0, ...}, ...})
    /home/runner/work/nerdctl/nerdctl/pkg/cmd/container/exec.go:63 +0x7e
github.com/containerd/nerdctl/v2/pkg/cmd/container.Exec.func1({0x13ec170?, 0xc0003c8500?}, {{0x13f48d8, 0xc0005ec2a0}, {0x7ffc44d0f6ca, 0x1a}, 0x0, 0x1})
    /home/runner/work/nerdctl/nerdctl/pkg/cmd/container/exec.go:49 +0x11e
github.com/containerd/nerdctl/v2/pkg/idutil/containerwalker.(*ContainerWalker).Walk(0xc00051b880, {0x13ec170, 0xc0003c8500}, {0x7ffc44d0f6ca, 0x1a})
    /home/runner/work/nerdctl/nerdctl/pkg/idutil/containerwalker/containerwalker.go:69 +0x347
github.com/containerd/nerdctl/v2/pkg/cmd/container.Exec({_, _}, _, {_, _, _}, {{0x0, 0x0, {0x12305bc, 0x1f}, ...}, ...})
    /home/runner/work/nerdctl/nerdctl/pkg/cmd/container/exec.go:53 +0x165
main.execAction(0xc000476608, {0xc00007f260, 0x5, 0x6})
    /home/runner/work/nerdctl/nerdctl/cmd/nerdctl/container_exec.go:141 +0x33c
github.com/spf13/cobra.(*Command).execute(0xc000476608, {0xc00003e0a0, 0x6, 0x6})
    /home/runner/go/pkg/mod/github.com/spf13/cobra@v1.8.1/command.go:985 +0xaca
github.com/spf13/cobra.(*Command).ExecuteC(0xc00039d808)
    /home/runner/go/pkg/mod/github.com/spf13/cobra@v1.8.1/command.go:1117 +0x3ff
github.com/spf13/cobra.(*Command).Execute(...)
    /home/runner/go/pkg/mod/github.com/spf13/cobra@v1.8.1/command.go:1041
main.xmain()
    /home/runner/work/nerdctl/nerdctl/cmd/nerdctl/main.go:137 +0x8f
main.main()
    /home/runner/work/nerdctl/nerdctl/cmd/nerdctl/main.go:120 +0x13

Steps to reproduce the issue

na

Describe the results you received and expected

na

What version of nerdctl are you using?

main

Are you using a variant of nerdctl? (e.g., Rancher Desktop)

None

Host information

No response

apostasie commented 3 months ago

FWIW:

apostasie commented 3 months ago

Here is a simple repro:

nerdctl --debug-full=true run -ti debian echo lo </dev/null |& cat
apostasie commented 3 months ago

Here is a repro for the compose one as seen on usernetes:

compose.yaml

services:
  web:
    image: node
    command: ["sleep", "Inf"]
nerdctl compose up -d
nerdctl compose exec web echo lol </dev/null |& cat
apostasie commented 3 months ago

FWIW, docker exec gives:

docker exec -ti 7e36c314c3bd59ba590035fc6c1c4d96a0e1a4981ae0e02f7e6bdaddfc0d8b92 echo lol </dev/null |& cat
the input device is not a TTY

While docker compose exec will just run with it:

docker compose exec web echo lol </dev/null |& cat

lol

@AkihiroSuda @fahedouch do you have an idea on how we should handle this?

My naive reading is that this is two fold:

  1. have a meaningful error when interactive and input is not a tty
  2. docker compose does not seem to exec with interactive, while we are apparently forcing it

and mmm...

docker compose exec -ti web echo lol </dev/null |& cat
lol
apostasie commented 3 months ago

Closing this. Although there are clearly other conditions that may trigger this error, the scope would be much broader and this specific issue here is fixed by the patch.

alitvak69 commented 2 months ago

It also happens when run -t in systemd unit.

Here is my systemd service unit /usr/local/bin/docker is a symbolic link to /usr/local/bin/nerdctl

[Unit] Description=DNS Master Internal After=containerd.service Requires=containerd.service

[Service] ExecStartPre=-/usr/local/bin/docker exec dns-master-internal stop ExecStartPre=-/usr/local/bin/docker rm dns-master-internal ExecStartPre=-/usr/local/bin/docker pull docker.xcastlabs.net/services/dns-host:latest ExecStart=/usr/local/bin/docker run -t --name=dns-master-internal \ --init \ --log-driver=journald \ --log-opt=tag={{.Name}} \ --env=DC=mke \ --env=DNSZONE_TYPE=master \ --env=DNSZONE_VIEW=internal \ --env=SERVICE_NAME=dns-master-internal \ --env=SERVICE_PORT=53 \ --env=BIND_DATA_DIR=/dns \ --cap-add=CAP_SYS_PTRACE \ --cap-add=CAP_NET_ADMIN \ --cap-add=CAP_NET_RAW \ --cap-add=CAP_NET_BIND_SERVICE \ --cap-add=CAP_SETUID \ --cap-add=CAP_SETGID \ --volume=/dns/master-internal:/dns:rw \ --net=vlan1225-dns-internal-masters \ \ docker.xcastlabs.net/services/dns-host:latest ExecStop=-/usr/local/bin/docker stop dns-master-internal SyslogIdentifier=dns-master-internal Restart=on-failure KillMode=mixed RestartSec=10s TimeoutStartSec=120 TimeoutStopSec=15

[Install] WantedBy=default.target

I tried privileged mode it is all the same. BTW, podman works just fine in the same setup

Here is the result in journalctl

The unit tmp-containerd\x2dmount3662397617.mount has successfully entered the 'dead' state. Sep 17 20:37:11 sbc21n1-mke dns-master-internal[147972]: panic: provided file is not a console Sep 17 20:37:11 sbc21n1-mke dns-master-internal[147972]: goroutine 1 [running]: Sep 17 20:37:11 sbc21n1-mke dns-master-internal[147972]: github.com/containerd/console.Current() Sep 17 20:37:11 sbc21n1-mke dns-master-internal[147972]: /home/runner/go/pkg/mod/github.com/containerd/console@v1.0.4/console.go:80 +0x94 Sep 17 20:37:11 sbc21n1-mke dns-master-internal[147972]: github.com/containerd/nerdctl/v2/cmd/nerdctl/container.runAction(0xc00049e608, {0xc000434dc0, 0x1, 0x14}) Sep 17 20:37:11 sbc21n1-mke dns-master-internal[147972]: /home/runner/work/nerdctl/nerdctl/cmd/nerdctl/container/container_run.go:392 +0x70a Sep 17 20:37:11 sbc21n1-mke dns-master-internal[147972]: github.com/spf13/cobra.(Command).execute(0xc00049e608, {0xc000144020, 0x14, 0x14}) Sep 17 20:37:11 sbc21n1-mke dns-master-internal[147972]: /home/runner/go/pkg/mod/github.com/spf13/cobra@v1.8.1/command.go:985 +0xaaa Sep 17 20:37:11 sbc21n1-mke dns-master-internal[147972]: github.com/spf13/cobra.(Command).ExecuteC(0xc00049e008) Sep 17 20:37:11 sbc21n1-mke dns-master-internal[147972]: /home/runner/go/pkg/mod/github.com/spf13/cobra@v1.8.1/command.go:1117 +0x3ff Sep 17 20:37:11 sbc21n1-mke dns-master-internal[147972]: github.com/spf13/cobra.(*Command).Execute(...) Sep 17 20:37:11 sbc21n1-mke dns-master-internal[147972]: /home/runner/go/pkg/mod/github.com/spf13/cobra@v1.8.1/command.go:1041 Sep 17 20:37:11 sbc21n1-mke dns-master-internal[147972]: main.xmain() Sep 17 20:37:11 sbc21n1-mke dns-master-internal[147972]: /home/runner/work/nerdctl/nerdctl/cmd/nerdctl/main.go:144 +0x8f Sep 17 20:37:11 sbc21n1-mke dns-master-internal[147972]: main.main() Sep 17 20:37:11 sbc21n1-mke dns-master-internal[147972]: /home/runner/work/nerdctl/nerdctl/cmd/nerdctl/main.go:127 +0x13 Sep 17 20:37:11 sbc21n1-mke systemd[1]: dns-master-internal.service: Main process exited, code=exited, status=2/INVALIDARGUMENT ░░ Subject: Unit process exited