Skip to content

Commit b4ba772

Browse files
Update README.md
1 parent bdadf83 commit b4ba772

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

README.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,73 @@
11
# docker-systemd
22
The docker containers with systemd support
3+
4+
## Introduction
5+
6+
The systemd is not supported by default in official docker images.
7+
8+
For example, users will get the following error when start `ssh` service using systemctl in docker container
9+
```
10+
root@f3ff816528f4:/# systemctl restart ssh
11+
System has not been booted with systemd as init system (PID 1). Can't operate.
12+
Failed to connect to bus: Host is down
13+
```
14+
15+
To fix the issue, some changes are needed when build the docker images.
16+
- For rockylinux, almalinux and oraclelinux, refer to https://hub.docker.com/r/rockylinux/rockylinux
17+
- For ubuntu24 and debian12, refer to https://blog.cloudabc.eu/linux/container/2024/10/27/ubuntu-docker-container-systemd/
18+
19+
## Build the docker images
20+
21+
If you use a non-root user, please add `sudo` before the commands.
22+
```
23+
docker build . --file Dockerfile.ubuntu24 --tag weizhouapache/docker-systemd:latest-ubuntu24
24+
docker build . --file Dockerfile.debian12 --tag weizhouapache/docker-systemd:latest-debian12
25+
docker build . --file Dockerfile.alma9 --tag weizhouapache/docker-systemd:latest-alma9
26+
docker build . --file Dockerfile.oracle9 --tag weizhouapache/docker-systemd:latest-oracle9
27+
docker build . --file Dockerfile.rocky9 --tag weizhouapache/docker-systemd:latest-rocky9
28+
```
29+
30+
You can find the docker images ready for use on:
31+
https://hub.docker.com/repository/docker/weizhouapache/docker-systemd/
32+
33+
## Create docker containers
34+
35+
Please note, the container name, hostname, network name (`net`) and ip address (`ip`) are optional.
36+
37+
### Rocky9/Alma9/Oracle9 containers
38+
39+
docker run -it -d \
40+
--privileged \
41+
--volume=/sys/fs/cgroup:/sys/fs/cgroup:rw \
42+
--cgroupns=host \
43+
--name alma9 \
44+
--hostname=alma9 \
45+
--net=<network name> \
46+
--ip=<ip address> \
47+
weizhouapache/docker-systemd:latest-alma9
48+
49+
### Ubuntu24/Debian12 containers
50+
51+
docker run -it -d \
52+
--privileged \
53+
--name ubuntu24 \
54+
--hostname=ubuntu24 \
55+
--net=<network name> \
56+
--ip=<ip address> \
57+
weizhouapache/docker-systemd:latest-ubuntu24
58+
59+
## Access the docker containers
60+
61+
Users can access the docker containers from the host by
62+
```
63+
docker exec -it ubuntu24 bash
64+
docker exec -it alma9 bash
65+
```
66+
67+
The `openssh-server` package has been installed in all containers, users can enable ssh by
68+
```
69+
echo "root:password" |chpasswd
70+
echo "PermitRootLogin yes" >>/etc/ssh/sshd_config
71+
systemctl enable ssh || systemctl enable sshd
72+
systemctl restart ssh || systemctl restart sshd
73+
```

0 commit comments

Comments
 (0)