Incus exec bash

Hi,
incus exec mycontainer bash
shows nothing, not even throws error.

What could go wrong ?

  • It works on my other containers
  • It used to work

Hi!

When you run incus exec mycontainer bash, then Incus will spawn (run) the process bash in that container. Not /bin/bash, nor /usr/bin/bash, but bash. This means that somehow the container should figure out if there is a bash and where it is.

Some images like Alpine do not come with bash and in that case you do get a suitable error message.

$ incus launch images:alpine/edge mycontainer
Launching mycontainer
$ incus exec mycontainer bash   
Error: Command not found
$

In the case of Alpine, you would exec the sh executable (it is in /bin/sh).

$ incus exec mycontainer sh
~ # exit
$ incus shell mycontainer 
mycontainer:~# exit
$ 

What’s this incus shell command? It’s an alias that does su -l for you (login shell). Note that you need to add -- when the command in the shell happens to have parameters. -- means that the shell on the host should stop processing parameters.

$ incus exec mycontainer su -l
Error: unknown shorthand flag: 'l' in -l
$ incus exec mycontainer -- su -l
mycontainer:~# exit
$

And now let’s answer your question. If a command that is incus exec-ed into an instance fails, then that command was indeed found in the container, but failed to produce any output. Somehow it crashed or something. In such a case, you try with other commands. You aim is to get any output from a command, as in incus exec mycontainer -- /bin/cat /etc/issue. If you do not get any output at all, then either the instance is messed up (and requires rebuilding), or something rare is happening and it’s specific to your system. Create a new container and check in there.

I should have say it before: no command is working on this container, which is running (it’s a jupyter notebook server I can reach by http).
Thanks for this instructive answer btw.

You can also get a shell through incus console. Does that work for you?

  • incus console mycontainer didn’t show a prompt up.
  • incus console mycontainer --show-log showed last lines of what I guess is some standard error. Enough to get that token I was looking for to log in in jupyter.

Still, I can’t log into that container.

just use :
incus exec mycontainer – login -p -f root
work on alpine ubuntu archlinux fedora