Hi!
There are a few ways to get a shell into a LXD container.
The container images from the ubuntu:
repository have by default a non-root account, ubuntu
.
Here are a few ways to get a shell.
You can run lxc shell mycontainer
It is an internal lxc alias
that gives you a root shell. It is one word shorted than doing lxc exec
.
You can run lxc exec mycontainer -- sudo --user ubuntu --login
You get a login shell as user ubuntu
.
For more on these, see https://blog.simos.info/using-command-aliases-in-lxd-to-exec-a-shell/
In the example you give, you would need to su - ubuntu
or su --login ubuntu
to get a properly setup shell, a login shell. Without that, you get weird Unix behaviour like the errors you point above.