'Is there a way to close the shell of the container after installing package?

I try to automate the configuration of raspios through bash script. My configurations are on network level and for that I need to install a package named vlan, so my try ist to use systemd-nspwan on mounted image.

My Problem is, when I start the container, a new shell is opened.

I need to install the package and after that close the container / shell to return to the root.

systemd-nspawn -D /mnt
if dpkg -l | grep vlan; then
    exit 1
else
    apt install vlan
fi

How can I exit the subshell so I can get back to root?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source