3

I wrote a github pull script inside the running container so that the container can get the updated codes. But how can I call this script from the host machine?

I have tried with something like this but with no success.

lxc exec container-name -- gitPull.sh
lxc exec container-name --sh -c "cd ~ && ll"

I have also tried to push a directory from host to lxd containers, but it won't copy the sub directory into the container.

Could any one help?

Many thanks!

1 Answer 1

4

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).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .