Dockerfile with Debian & systemd

i am creating a Dockerfile that downloads Debian:bookworm and i running a program through apt, but when it finishes the build, i am getting the following error:

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

how do i overcome this issue, please?

A container is not a virtual machine so you can’t use it like that. Systemd is something that runs as the very first process on top of a Linux kernel to handle all the other processes in most of the modern Linux distributions, but not in an application container which is an isolated environment for a process and not an entire operating system.

If you want something that allows you to install almost everything as you would do on a physical machine or in a virtual machine, you can try “system containers”. Docker is for application containers. LXD and Incus are for system containers.

In a Docker container you (almost always) run processes without Systemd. If you need multiple processes in a single container, you can try Supervisor or s6-init for example.

If you want to know why you should not use Systemd in a Docker container, you can search for systemd on the forum, or read my tutorial that includes systemd as well

I never tried, but Podman claims to be able to run Systemd more easily

What exactly do you want to run in a container? You can use a base image which already contains what you need and built for starting the process properly.

1 Like

What i am trying to achieve is to build Jenkins docker by using the repo, not the Java (WAR file). That will give me the ability to upgrade it via apt-get. Here is my Dockerfile:

#Ude Debian slim latest
FROM debian:bookworm-slim

#Update & upgrade
RUN apt-get update && apt-get upgrade -y

#Install needed packages
RUN apt-get install -y --no-install-recommends gnupg openjdk-17-jdk fontconfig openjdk-17-jre apt-transport-https wget curl screen htop nano vim sudo procps lsb-release

#Keyring & repo config
RUN wget -O /usr/share/keyrings/jenkins-keyring.asc
RUN echo "deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc]" binary/ | tee /etc/apt/sources.list.d/jenkins.list > /dev/null

# Install Jenkins
RUN apt update && apt install jenkins -y

EXPOSE 8080/tcp
EXPOSE 8080/udp
EXPOSE 50000/tcp
EXPOSE 50000/udp

I would like to be able to directly hit from the browser the System’s IP (where docker is running) http://IP_address:8080 and get jenkins. I have seen that the Jenkins is already available, but it does not use the apt-get, rather it uses the java environment.

Why bother setting up a Jenkins image when there is an official image (link)?

Dear @bluepuma77, thanks a lot for the reply, but i am afraid you missed my statement: to be able to use the apt-get utility and update jenkins, instead of getting pinned to a certain version and manually downloading a Java file and executing it.

That is probably the right way anyway, at least in this case. APT repositories change, packages disappear and you have no total control over which version you install. I feel your real question is how you can properly update a Docker image, using APT is just a way you imagined you could solve it.

I don’t think he missed your point. He is trying to tell you how you should work with containers. I recommend taking his words, nobody talks about downloading a WAR file, just use an already existing image. When you want to update it, you pull a new version. You can decide how specific image version you use, you can even automate the update with a proper pipeline.

Use official existing images when you can, learn about crating your own images, customize existing images and make your own base image only when you know why you need it.

You chose to use containers, and that’s the way :slight_smile: Don’t make your life harder by sticking to solutions you used without containers.

The title of the topic is “Dockerfile with Debian & Systemd”. I don’t know anyone who uses systemd in a container in production. I used it only in special cases years ago, but Jenkins is not really special :slight_smile: