How do I run a listening program (specifically unoconv as a listener) inside a container using systemd-nspawn, so that it can run in the background (without a console) and be reached by other processes? For example in a perfect world it would be as easy as this:

# something like this to start the container and program in background
systemd-nspawn -D <container path> --background <unoconv --listener> 

# something like this to connect to container and execute command
systemd-run --machine <machine name> <unoconv -f pdf file.txt>

The furthest I've got so far is using Taming systemd-nspawn for running containers, which gets the container running in the background with machinectl. However,

sudo systemd-run --machine <machine name> ls

fails with the error:

Failed to create bus connection: Permission denied.

My question is two-fold. One, can you solve this error? Or two (preferably) can you give me a simpler way to start and connect to a container and run commands?

(I'm running Ubuntu Xenial on a secure machine with no internet access)

1 Answer 1


I think it depends on how often you want to run the container and when.

If this is something you want running as soon as Ubuntu loads, every time the computer starts up, then I'd recommend trying the Startup Applications settings. You can add anything that functions as a terminal command as a startup "application" process. Alternatively, you can put together a script and then run the script as the startup process, which would give you finer control. (Keep in mind that items in the Startup Applications list are executed in alphabetical order by the Name field, so if order of execution is important, either name it accordingly or just create a startup script and make that the only call.)

If you want to run the program at a specific reoccurring time/date, I'd recommend putting together a cron job to do the same thing.

If you want to run it on demand... not sure about that. I'm not too familiar with systemd-nspawn; maybe this article or this article will help.

For question 1, I'm stumped. Typo in the machine name, maybe? Mismatch between container OS permissions and systemd-run authentication options? You could try sshd or a docker container if nothing else works.

Granted, if you're actually typing it like "--machine <machine name>", changing it to "--machine=<machine name>" might just fix it. :P

You must log in to answer this question.

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