I have an Ubuntu 18.04 image runing on my docker container. I login into it and installed Openresty
. also installed systemd
. When I use command systemctl
I get this error:
System has not been booted with systemd as init system (PID 1). Can't operate.
How can I fix it?
How to fix 'System has not been booted with systemd' error? The simple answer is to not use the systemctl command. Instead, use the equivalent sysvinit command.
To boot under systemd, select the boot menu entry that you created for the purpose. If you didn't bother to create one, just select the entry for your patched kernel, edit the kernel command line directly in grub and add init=/lib/systemd/systemd.
To start systemd inside a Docker container a few pre-requisites have to be met: systemd has to be installed inside the container of course. It provides e.g. the /sbin/init binary. Using the fedora:34 Docker image this can be achieved by installing httpd for example (the Apache web server).
If I understand the OP, he is trying to run systemctl within the container. This does not work because systemd is not running within the container to begin with. It cannot be done in unprivileged containers. There is another question here in SO about why he should not run systemd within a container.
I quickly googled and found this 2014 page about using systemd within a container in docker, where there is a short explanation. The fix is to use a privileged container (running docker run --privileged ...
), which is arguably a bad idea but might suit the OP. There is a 2019 update of that last article, and the bottomline is they developed their own container engine (so no docker).
The obvious solution would be to have a single service, so no need for systemd, although that might not be possible in the OP's case.
In summary, possible solutions:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With