Ubuntu 20.04 with systemd

I’m new to Docker. I’m trying to containerize my server. My Ubuntu 20.04 server utilizes systemd. When I create a container based on ubuntu, it doesn’t have systemd. This is my Dockerfile:

FROM ubuntu:focal

Update package list and fix broken dependencies

RUN apt update && apt -f install

Install systemd

RUN apt install -y systemd

When I run the container with: docker run -it m9kubuntu /bin/bash
I get a Terminal. systemd is there but Ubuntu doesn’t seem to be using it:

root@9376c946b4c3:/# which systemd
/usr/bin/systemd
root@9376c946b4c3:/# systemctl status
System has not been booted with systemd as init system (PID 1). Can’t operate.
Failed to connect to bus: Host is down

FIRST QUESTION: I would expect Ubuntu 20.04 to have systemd already since it’s such an integral part of Ubuntu. Why isn’t it there out of the box? How should I build an Ubuntu container that has a working systemd?

SECOND QUESTION: My application on my current server uses MySQL, tomcat9, ActiveMQ, etc. Should I be trying to build one container that has all my services in it or should I be building multiple containers that provide the services and stitch them together?

Thanks!
Todd

Because the distribution base images are just a set of libraries, binaries, and config files that make up the core of a distribution, but are not a full OS. A container created from an image does not contain a kernel, does not “boot” or start process managers like systemd, it only starts whatever is defined as entrypoint and/or command. A container is supposed to ideally run a single process.

I strongly suggest taking inspiration from other existing images for the application you aim to run as container. Search for an image on Dockerhub, sometimes their Github repositories are directly linked, or can usually be found easily by googling the image name.

Rule of thumb: components that interact with each other over the network belong in separate containers.

An application that consists of multiple components can be orchestrated using docker compose (single-node multi container orchestration), or docker stack deploy (multi-node multi-container orchestration).

Docker provides dns-based service discovery, which allows containers in a user defined network to communicate with all other containers in the same network by using their service or container name. Note: localhost of a container is not the localhost of the host, or any other container.

1 Like