How do I run a Docker container that uses SystemD from the latest version of Ubuntu (18.10)?
Asked Answered
N

3

4

I'm trying to execute a Docker image built using 'ubuntu:latest' and I keep getting SystemD error messages when I run the container:

System has not been booted with systemd as init system (PID 1). Can't operate.

If I try this solution and spawn the container using docker run -it -e container=docker your-image-name /sbin/init, I get the following error:

Failed to mount tmpfs at /run: Operation not permitted
Failed to mount tmpfs at /run/lock: Operation not permitted
[!!!!!!] Failed to mount API filesystems, freezing.
Freezing execution.

What should I try differently?

Nick answered 12/12, 2018 at 20:36 Comment(8)
You generally don't want to run a process manager like systemd (or anything else) inside a container. What exactly are you trying to do?Crus
I'm trying to startup an Nginx and SSHD container. How do you avoid SystemD if all the Linux distros have already moved to it? seems like this is an issue that should have gotten ironed out already?Nick
It has been ironed out. You don't use a processor manager in your container. You start the service you want, and that's it. Take a look at any of the official containers for things like nginx, httpd, mysql, etc. You don't run ssh inside your container; that's what docker exec is for.Crus
Hmm okay, thanks. I need SSH because I use Ansible to send it config files. :)Nick
It sounds like you're managing your container like a VM. I strongly recommend against that. The most you should be doing with ansible is building an image and running the container.Livery
Not so much. The config files are going into the container to be hosted by the Nginx server. It's pretty basic actually.Nick
You typically provide that configuration before the container starts up, maybe injecting them using a docker run -v option. Running an ssh daemon in a container IME is pretty unusual (and presents some tricky management problems).Stereobate
These are config files that get hosted by Nginx. They're not used by the Docker container itself. I found that if my host OS is running Bionic or later, the same error messages disappear using the /sbin/init method from above.Nick
E
3

You can solve this using a different version, like 16.04:

docker run -d \
  -h ubuntu \
  --name ubuntu \
  --privileged \
  docker.io/library/ubuntu:16.04 /sbin/init

After run, you can accessed using the follow command:

docker exec -it ubuntu /bin/bash

This version uses systemd.

Edithe answered 10/1, 2020 at 19:39 Comment(0)
F
2

In order to run ubuntu 18 systemd inside docker, you can use this:

Run container:

docker run -d --name stack_overflow_53750952 --privileged -v /sys/fs/cgroup:/sys/fs/cgroup:ro jrei/systemd-ubuntu:18.04

Enter in container:

docker exec -it stack_overflow_53750952 bash

Then as you can see: screenshot of systemd running inside the container

Fermata answered 9/4, 2020 at 0:10 Comment(0)
N
-5

Upgrade to Ubuntu Bionic and try /sbin/init method

Nick answered 12/12, 2018 at 22:5 Comment(1)
My question was for Ubuntu, not CentOSNick

© 2022 - 2024 — McMap. All rights reserved.