Lxc exec resulted in command running on host


When running the following command on the host:

lxc exec c01n2 – apt update && apt upgrade -y && apt autoremove && reboot

Expected behavior is that the entire line gets executed inside the VM, but the host was restarted.

Please note that the apt autoremove command would probably have required “-y” and hence probably that is the root of the problem, nonetheless, I don’t think the host should have been restarted and the error should have been caught and the execution interrupted…

Sadly every time the hosts restart I have to wait several minutes until the restart is completed, so I can’t test variants fast…

I see clearly now
As soon as you &&, the command is completely new and hence executed on the host
The proper command if you intend to run this entirely on the Container or VM would be:

lxc exec c01n2 – apt update && lxc exec c01n2 – apt upgrade -y && lxc exec c01n2 – apt autoremove -y && lxc exec c01n2 – reboot

Which… surprise, surprise, works flawlessly!

You can also invoke the shell as the command you run and pass the multiple commands to run as a quoted argument