在docker中启动服务报错:New main PID 558 does not belong to service

Posted 为何一再沦落

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在docker中启动服务报错:New main PID 558 does not belong to service相关的知识,希望对你有一定的参考价值。


在docker中启动服务报错: New main PID 558 does not belong to service, and PID file is not owned by root. Refusing.

类似主要错误如下所示:

Job for mongod.service failed because a timeout was exceeded.
See "systemctl status mongod.service" and "journalctl -xe" for details.

● mongod.service - MongoDB Database Server
Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; vendor preset: disabled)
Active: failed (Result: timeout) since Wed 2021-01-27 03:47:51 UTC; 1min 4s ago
Docs: https://docs.mongodb.org/manual
Process: 3744 ExecStart=/usr/bin/mongod $OPTIONS (code=exited, status=0/SUCCESS)
Process: 3743 ExecStartPre=/usr/bin/chmod 0755 /var/run/mongodb (code=exited, status=0/SUCCESS)
Process: 3742 ExecStartPre=/usr/bin/chown mongod:mongod /var/run/mongodb (code=exited, status=0/SUCCESS)
Process: 3741 ExecStartPre=/usr/bin/mkdir -p /var/run/mongodb (code=exited, status=0/SUCCESS)

Jan 27 03:46:21 c352fd7c55f0 systemd[1]: Starting MongoDB Database Server...
Jan 27 03:46:21 c352fd7c55f0 mongod[3744]: about to fork child process, waiting until server is ready for connections.
Jan 27 03:46:21 c352fd7c55f0 mongod[3744]: forked process: 3746
Jan 27 03:46:22 c352fd7c55f0 mongod[3744]: child process started successfully, parent exiting
Jan 27 03:46:22 c352fd7c55f0 systemd[1]: mongod.service: New main PID 3746 does not belong to service, and PID file is not owned by root. Refusing.
Jan 27 03:46:22 c352fd7c55f0 systemd[1]: mongod.service: New main PID 3746 does not belong to service, and PID file is not owned by root. Refusing.
Jan 27 03:47:51 c352fd7c55f0 systemd[1]: mongod.service: Start operation timed out. Terminating.
Jan 27 03:47:51 c352fd7c55f0 systemd[1]: mongod.service: Failed with result timeout.
Jan 27 03:47:51 c352fd7c55f0 systemd[1]: Failed to start MongoDB Database Server.

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

错误信息

● 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.12345678910111213141516

解决方法:
挂载宿主机 cgroup目录,启动时加上 -v /sys/fs/cgroup:/sys/fs/cgroup

在docker中使用yum安装mysql后,启动MySQL卡住:

[root@lhrc76mysql soft]# systemctl restart mysqld
^C
[root@lhrc76mysql soft]# systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: activating (start) since Fri 2020-11-13 09:26:58 CST; 32s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 916 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
Process: 901 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
CGroup: /docker/1b18ed8e35082a6efebad26cbca2b100f5e80055f61fe1688c3aa2ed4ae042a4/system.slice/mysqld.service
└─918 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
Nov 13 09:26:58 lhrc76mysql systemd[1]: Starting MySQL Server...
Nov 13 09:26:58 lhrc76mysql systemd[1]: New main PID 918 does not belong to service, and PID file is not owned by root. Refusing.
Nov 13 09:26:58 lhrc76mysql systemd[1]: New main PID 918 does not belong to service, and PID file

解决:

挂载宿主机 cgroup 目录,启动时加上 -v /sys/fs/cgroup:/sys/fs/cgroup

docker rm -f centos_1

docker run -d --name centos_1 \\
-p 3306-3406:3306-3406 -p 222:22 \\
-v /sys/fs/cgroup:/sys/fs/cgroup \\
--privileged=true \\
ycj520/centos /usr/sbin/init

docker exec -it centos_1 bash

如果可以,恰好你愿意,我们…………


以上是关于在docker中启动服务报错:New main PID 558 does not belong to service的主要内容,如果未能解决你的问题,请参考以下文章

docker-ce 配置初始化后服务启动报错

Docker 安装完启动服务报错

docker配置镜像仓库报错

CentOS7 docker-compose启动报错

Docker-docke服务启动报错:Job for docker.service failed because the control process exited with error code.

Error response from daemon ... no space left on device docker启动容器服务报错