在docker的centos镜像中使用systemctl启动slapd服务报错

前言

使用docker搭建服务环境,拉取了一个Centos7镜像,在镜像中使用systemctl命令启动sladpd服务,已经使用--privileged=true启用特权模式,但还是报错。 docker 启动命令如下:

1
2
docker run -itd --name=ldap --privileged=true -v  \ 
-p 80:80 -p 389:389 centos:7 /usr/sbin/init

错误信息

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
● slapd.service - OpenLDAP Server Daemon
Loaded: loaded (/usr/lib/systemd/system/slapd.service; disabled; vendor preset: disabled)
Active: failed (Result: timeout) since Fri 2020-01-03 05:51:22 UTC; 2min 43s ago
Docs: man:slapd
man:slapd-config
man:slapd-hdb
man:slapd-mdb
file:///usr/share/doc/openldap-servers/guide.html

Jan 03 05:49:45 d5450c0c7b3e systemd[1]: Starting OpenLDAP Server Daemon...
Jan 03 05:49:45 d5450c0c7b3e systemd[1]: New main PID 558 does not belong to service, and PID file is not owned by root. Refusing.
Jan 03 05:49:45 d5450c0c7b3e systemd[1]: New main PID 558 does not belong to service, and PID file is not owned by root. Refusing.
Jan 03 05:51:22 d5450c0c7b3e systemd[1]: slapd.service start operation timed out. Terminating.
Jan 03 05:51:22 d5450c0c7b3e systemd[1]: Failed to start OpenLDAP Server Daemon.
Jan 03 05:51:22 d5450c0c7b3e systemd[1]: Unit slapd.service entered failed state.
Jan 03 05:51:22 d5450c0c7b3e systemd[1]: slapd.service failed.

解决方法:

挂载宿主机cgroup目录,启动时加上-v /sys/fs/cgroup:/sys/fs/cgroup 完整启动命令如下:

1
2
3
docker run -itd --name=ldap --privileged=true \
-v /sys/fs/cgroup:/sys/fs/cgroup \
-p 80:80 -p 389:389 centos:7 /usr/sbin/init

在docker的centos镜像中使用systemctl启动slapd服务报错
https://www.shangyexin.com/2020/01/20/docker-slapd/
作者
Yasin
发布于
2020年1月20日
许可协议