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.

Introduction & Quick Summary
Any systemctl call fails immediately inside a container, on WSL, or in a chroot:
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is downsystemctl 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 bashthensystemctl restart nginx.- A Dockerfile that installs a package and runs
systemctl enableduring the build. - WSL2 distributions before
systemd=truewas added to/etc/wsl.conf. - A chroot or
debootstrapenvironment 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;
'bash
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is downThe same environment with the process started directly, which is how containers are meant to work:
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:
| Output | Meaning | Next step |
|---|---|---|
not been booted with systemd | PID 1 is not systemd | use the container's own start command |
Failed to connect to bus: No such file or directory | no bus socket | not a service-manager environment |
Failed to connect to bus: Host is down | bus path exists, nothing listens | same cause, different image state |
Unit nginx.service could not be found | systemd is running, unit is not installed | install the unit or use the image's init |
Access denied | no permission on the bus | you need root inside the container |
Inspect what you actually have:
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/nullKey Comparison Table
| Environment | Recommended approach | Why |
|---|---|---|
| Docker container | run the process as PID 1 with exec form CMD | signals and exit codes propagate |
| Several processes in one container | supervisord or s6-overlay | reaps children, restarts crashed processes |
| Image that really needs systemd | systemd-enabled base image plus cgroup settings | systemd requires cgroup and namespace support |
| WSL2 | systemd=true in /etc/wsl.conf | WSL provides a real PID 1 slot |
| Chroot for image building | chroot plus direct commands, no systemctl | no boot happened in the chroot |
| CI container job | start services with their own binary | the runner is PID 1, not your shell |
Trade-offs of running systemd inside a container:
| Option | Startup cost | Complexity | Fits |
|---|---|---|---|
Direct CMD ["app"] | lowest | lowest | one process, the normal case |
tini or dumb-init as PID 1 | low | low | app must run as PID 1 but needs reaping |
| supervisord | medium | medium | two or three long-running processes |
| systemd as PID 1 | high | high | lifting 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.
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 environmentInside 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.
# /etc/wsl.conf
[boot]
systemd=truewsl --shutdown
wsl -d Ubuntu
systemctl is-system-runningAfter 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.
# 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=0RUN 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 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.
# inside an image build or a chroot
ln -sf /lib/systemd/system/nginx.service /etc/systemd/system/multi-user.target.wants/nginx.serviceIn a CI container job, start the service binary in the background and wait for the port, rather than enabling it:
nginx -g 'daemon off;' &
until curl -sf http://127.0.0.1:80/ >/dev/null; do sleep 1; doneCheck 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 documentationThe Linux documentation that defines the behaviour this guide explains.
Try matching browser tools
All toolsSmall utilities that fit Linux work — they run entirely in this browser tab, so nothing you paste leaves your device.
Related Linux guides
All Linux guidesnginx 502 Bad Gateway: upstream connection refused
The log line names the address and errno, which is the diagnosis. Fix the host, the start-up order, the buffers, or the timeout that actually fired.
Linux: Read-only file system (EROFS) on a mounted volume
EROFS is a mount condition, not a permission error. Read the kernel log first: I/O errors, a full thin pool, an ro fstab entry or a read-only root.
Linux Networking Diagnostics: ss, ip, dig, curl, and TCP Troubleshooting
A layer-by-layer path from interface to TLS that localises a failure in five commands, with the socket states and curl timings that identify each cause.
apt: The repository does not have a Release file
apt disables any repository whose Release file returns 404. Correct the suite name, move an end-of-life release to the archive host, or remove a dead repo.
More in Linux
All Linux guidesThe guides filed next to this one in Linux, in library order.