Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker System has not been booted with systemd as init system

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?

like image 205
Abdol Seed Avatar asked Dec 24 '19 08:12

Abdol Seed


People also ask

How do I fix system has not been booted with systemd as init system?

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.

How do I boot to systemd as init?

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.

Can you run systemd in docker?

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).


1 Answers

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:

  • not to use systemd
  • use a privileged container
  • not to use docker
like image 87
Javier Gonzalez Avatar answered Oct 24 '22 06:10

Javier Gonzalez