From my understanding lxc exec should work similar to passing commands via SSH. However I cannot issue multiple commands in parenthesis:
Runs first command in the container, and the second on on the host:
lxc exec container -- ls -a & top
Doesn't work
lxc exec maas -- "ls -a & top"
lxc: attach.c: lxc_attach_run_command: 1107 No such file or directory - failed to exec 'ls -a & top'
Yeah, we can't make that part work like ssh. The reason for this is that ssh knows what your shell is inside the container, we don't.
When ssh detects shell specific characters being used, it spawns the shell and pass the command to it, rather than spawning it itself.
Anyway, the result is, we can't implement this behavior in LXD.
The good news though is that you can do it yourself on the client with:
lxc exec maas -- /bin/sh -c "ls -a & top"
Assuming that /bin/sh is a valid shell.
Most helpful comment
Yeah, we can't make that part work like ssh. The reason for this is that ssh knows what your shell is inside the container, we don't.
When ssh detects shell specific characters being used, it spawns the shell and pass the command to it, rather than spawning it itself.
Anyway, the result is, we can't implement this behavior in LXD.
The good news though is that you can do it yourself on the client with:
lxc exec maas -- /bin/sh -c "ls -a & top"
Assuming that /bin/sh is a valid shell.