When you run lxc exec
on an Ubuntu container, you get a root shell and your home directory is /root
.
If you are using a non-root account (like ubuntu
from ubuntu:18.04
), then you can get a shell into that account with
lxc exec mycontainer -- sudo --login --user ubuntu
And if you want to run a command as user ubuntu
, then you can
$ lxc exec mycontainer -- sudo --login --user ubuntu whoami
ubuntu
You have a typo in lxc exec container-name --sh -c "cd ~ && ll"
. There should be a space after --
because --
is a special instruction to your host's shell which says that the lxc exec
command should stop reading any subsequent options as options for lxc exec
. For example, the following is wrong, because the -l
option is processed by lxc exec
instead of being given verbatim as a command to run in the container.
$ lxc exec mycontainer ls -l
Error: unknown shorthand flag: 'l' in -l
The correct would be
$ lxc exec mycontainer -- ls -l
You can push a directory from the host to the container by running
$ lxc file push --recursive /home/myusername/myfiles/ mycontainer/home/ubuntu/
The directory tree /home/myusername/myfiles/
on the host will get copied into the container mycontainer
inside the (existing) directory /home/ubuntu/
(in that container).