Pages

Topics

Tools

↑↓navigate↵openescclose
All guides

Linux: System has not been booted with systemd as init system

systemctl fails in containers and WSL because PID 1 is not systemd. Use the container's own init, enable systemd in WSL, or run a small service manager.

~5 min readLinux
#linux#systemd#docker#wsl
Bold white headline reading NO SYSTEMD with a Linux container crate showing an empty cyan PID 1 slot.

Introduction & Quick Summary

Any systemctl call fails immediately inside a container, on WSL, or in a chroot:

code
System has not been booted with systemd as init system (PID 1). Can't operate. Failed to connect to bus: Host is down

systemctl is not a service manager itself. It is a client that talks to systemd over D-Bus, and it refuses to run when process ID 1 is not systemd. In Docker, Kubernetes, GitHub Actions container jobs, and default WSL2, PID 1 is your application or a minimal init such as tini or dumb-init, so there is no systemd to talk to.

Where it appears:

  • docker exec -it app bash then systemctl restart nginx.
  • A Dockerfile that installs a package and runs systemctl enable during the build.
  • WSL2 distributions before systemd=true was added to /etc/wsl.conf.
  • A chroot or debootstrap environment used to prepare an image.
  • CI runners that execute steps inside a container image.

Quick answer: in a container, start the process directly and do not use systemctl; in WSL2, enable systemd in /etc/wsl.conf and restart the distribution; only run systemd as PID 1 in a container when the image was built for it.

Core Mechanics, Signatures & Reproducible Setup

systemd is PID 1 on a normal Linux boot. It owns the service manager bus socket at /run/systemd/private and the system bus at /run/dbus/system_bus_socket. systemctl checks both the PID 1 identity and the bus connection, which is why the failure prints two lines: the identity check fails first, then the bus connect.

# reproduce in any standard image docker run --rm -it ubuntu:24.04 bash -lc ' ps -p 1 -o comm=; systemctl status; '
code
bash System has not been booted with systemd as init system (PID 1). Can't operate. Failed to connect to bus: Host is down

The same environment with the process started directly, which is how containers are meant to work:

dockerfile
FROM ubuntu:24.04 RUN apt-get update && apt-get install -y --no-install-recommends nginx && rm -rf /var/lib/apt/lists/* EXPOSE 80 CMD ["nginx", "-g", "daemon off;"]

The container has nginx running, no systemd, and no need for either. Related diagnostics and what they mean:

OutputMeaningNext step
not been booted with systemdPID 1 is not systemduse the container's own start command
Failed to connect to bus: No such file or directoryno bus socketnot a service-manager environment
Failed to connect to bus: Host is downbus path exists, nothing listenssame cause, different image state
Unit nginx.service could not be foundsystemd is running, unit is not installedinstall the unit or use the image's init
Access deniedno permission on the busyou need root inside the container

Inspect what you actually have:

bash
ps -p 1 -o pid,comm,args ls -l /run/systemd/system 2>/dev/null || echo "no systemd runtime" command -v service systemctl supervisord tini 2>/dev/null cat /etc/wsl.conf 2>/dev/null

Key Comparison Table

EnvironmentRecommended approachWhy
Docker containerrun the process as PID 1 with exec form CMDsignals and exit codes propagate
Several processes in one containersupervisord or s6-overlayreaps children, restarts crashed processes
Image that really needs systemdsystemd-enabled base image plus cgroup settingssystemd requires cgroup and namespace support
WSL2systemd=true in /etc/wsl.confWSL provides a real PID 1 slot
Chroot for image buildingchroot plus direct commands, no systemctlno boot happened in the chroot
CI container jobstart services with their own binarythe runner is PID 1, not your shell

Trade-offs of running systemd inside a container:

OptionStartup costComplexityFits
Direct CMD ["app"]lowestlowestone process, the normal case
tini or dumb-init as PID 1lowlowapp must run as PID 1 but needs reaping
supervisordmediummediumtwo or three long-running processes
systemd as PID 1highhighlifting a VM workload into a container

Practical Edge Cases, Error Fixes & Deep Dive Code Examples

1. Confirm where the command is running

The same error has different fixes, so identify the environment first.

bash
ps -p 1 -o comm= # systemd -> a real boot, systemctl should work # bash -> container or chroot # tini -> container with an init shim # init -> WSL or minimal environment

Inside a container, docker exec runs in the same namespaces as PID 1, so the check is valid there. On a host, use systemctl is-system-running to see whether systemd finished booting.

2. Enable systemd in WSL2

WSL2 runs a real init slot and can host systemd, but only when asked. Newer distributions ship the setting commented out.

ini
# /etc/wsl.conf [boot] systemd=true
powershell
wsl --shutdown wsl -d Ubuntu systemctl is-system-running

After the restart, systemctl works and services enabled with systemctl enable start with the distribution. If it still reports the old message, check that /etc/wsl.conf has no BOM and that the distribution is WSL2 (wsl -l -v).

3. Use the container's own init for multiple processes

When a container genuinely needs two processes, a supervisor is cheaper and more predictable than systemd.

ini
# supervisord.conf [supervisord] nodaemon=true logfile=/dev/null pidfile=/run/supervisord.pid [program:api] command=node /app/server.mjs autorestart=true stdout_logfile=/dev/stdout stdout_logfile_maxbytes=0 stderr_logfile=/dev/stderr stderr_logfile_maxbytes=0 [program:worker] command=node /app/worker.mjs autorestart=true stdout_logfile=/dev/stdout stdout_logfile_maxbytes=0
dockerfile
RUN apt-get update && apt-get install -y --no-install-recommends supervisor && rm -rf /var/lib/apt/lists/* CMD ["supervisord", "-c", "/etc/supervisord.conf"]

Logs go to stdout and stderr so docker logs still shows them; writing to files inside the container hides them from every log collector.

4. Run systemd inside a container when you must

Lifting a VM image into a container needs systemd, cgroups, and a writable /run. The supported combinations are narrow.

docker run --rm -it \ --privileged \ --cgroupns=host \ -v /sys/fs/cgroup:/sys/fs/cgroup:rw \ --tmpfs /run --tmpfs /run/lock \ jrei/systemd-ubuntu:24.04
dockerfile
# Dockerfile for a systemd-based image FROM ubuntu:24.04 ENV container=docker RUN apt-get update && apt-get install -y --no-install-recommends systemd systemd-sysv && rm -rf /var/lib/apt/lists/* STOPSIGNAL SIGRTMIN+3 CMD ["/sbin/init"]

STOPSIGNAL SIGRTMIN+3 lets systemd shut down cleanly on docker stop. This setup is heavier than the workload usually needs; prefer it only for the migration period.

5. Handle chroots, CI, and devcontainers

There is no boot in a chroot, so systemctl enable in a Dockerfile build has nothing to enable. Enable units by symlink instead.

bash
# inside an image build or a chroot ln -sf /lib/systemd/system/nginx.service /etc/systemd/system/multi-user.target.wants/nginx.service

In a CI container job, start the service binary in the background and wait for the port, rather than enabling it:

bash
nginx -g 'daemon off;' & until curl -sf http://127.0.0.1:80/ >/dev/null; do sleep 1; done

Check the port answer with curl and confirm a clean exit status with the status codes reference when the step fails.

Common Compilation/Runtime Mistakes & Version Gotchas

Installing systemd and expecting it to run. Installing the package does not make it PID 1. Unless the image entrypoint is /sbin/init, PID 1 remains whatever CMD started.

Enabling a unit during docker build. systemctl enable needs the bus and PID 1 check, so it fails at build time or, worse, silently changes nothing. Use the symlink form or start the process in CMD.

Using shell form CMD so signals never arrive. CMD nginx runs through /bin/sh -c, so the shell is PID 1 and docker stop sends SIGTERM to the shell, not to nginx. Use the exec form CMD ["nginx", "-g", "daemon off;"].

Reaching for --privileged first. It often makes systemd start, and it also gives the container every capability on the host. Prefer the multi-process supervisor or the official image's built-in entrypoint.

Confusing service with systemctl. service nginx start works in some Debian-based images because it falls back to an init script, then fails in images that only ship systemd units. systemctl always needs the bus.

Version differences. WSL2 required systemd=true from WSL 0.67.6 onward and does not support it in WSL1 at all. Docker Engine 20.10 and later default to a private cgroup namespace, which systemd-based images must override with --cgroupns=host. Kubernetes supports shareProcessNamespace and a systemd-based image, but the kubelet still owns the pod lifecycle, so systemd inside a pod manages only its own units.

A quick decision rule. If the environment gives you one process, use that one process. If it gives you a boot, use systemd. Most of the time you are in the first case, and the error is telling you that systemctl is the wrong tool rather than that something is broken.

Reference material: Docker multi-service containers and systemd.

Official references

primary documentation

The Linux documentation that defines the behaviour this guide explains.

Try matching browser tools

All tools

Small utilities that fit Linux work — they run entirely in this browser tab, so nothing you paste leaves your device.

All Linux guides

More in Linux

All Linux guides

The guides filed next to this one in Linux, in library order.