i've just been introduced to systemd-nspawn, and for some reason the simple thing of being able to write a script that does things inside the nspawn rootfs, like, you know, automatic setup, a la Dockerfile - didn't seem to be a problem that anyone was bothering to publish much of a solution about.

based on this https://superuser.com/questions/1242978/start-systemd-nspawn-and-execute-commands-inside/1243010#1243010 - and btw i duly created an account and submitted edits to the leading answer that fix it up so it actually is correct for current versions of systemd-nspawn.

this is an example of a little piece of script that dives into a rootfs in a folder `mysql` in the current directory:

infuriatingly, some silly people don't see the sense in markdown, which doesn't change anything if you don't specifically use it, for non-marked-up text, isn't the default format for notes. but whatever. so that's why this is pig ugly, but you can c&p it for your own uses:

#!/usr/bin/bash

systemd-nspawn --pipe -q -D mysql /usr/bin/bash << EOF

apt update

apt -y full-upgrade

EOF

#devstr

Reply to this note

Please Login to reply.

Discussion

No replies yet.