Docker Container Centos7 systemctl 提示 Failed to get D-Bus connection: Operation not permitted

时间:2021-11-05 01:08:54

操作环境

[root@localhost ~]# docker version
Client:
 Version:      17.03.1-ce
 API version:  1.27
 Go version:   go1.7.5
 Git commit:   c6d412e
 Built:        Fri Mar 24 00:36:45 2017
 OS/Arch:      linux/amd64

Server:
 Version:      17.03.1-ce
 API version:  1.27 (minimum version 1.12)
 Go version:   go1.7.5
 Git commit:   c6d412e
 Built:        Fri Mar 24 00:36:45 2017
 OS/Arch:      linux/amd64
 Experimental: false

[root@centos-cloudera-1 /]# cat /etc/redhat-release 
CentOS Linux release 7.4.1708 (Core) 

问题描述

在centos 7.4 container centos-cloudera-1 中部署mariadb,使用systemctl 启动mariadb提示如下:

[root@centos-cloudera-1 /]# systemctl start mariadb
Failed to get D-Bus connection: Operation not permitted


解决方法

1.新建container添加/usr/sbin/init以及privileged参数

[root@localhost ~]# docker run -ti --privileged --name centos-cloudera-5 --hostname centos-cloudera-5 514d36e6e77d /usr/sbin/init

2.在启动该container后,需要对其进行stop/start操作,如果不进行stop/start操作,就无法进入该container,不清楚具体元婴

[root@localhost ~]# docker stop centos-cloudera-5
centos-cloudera-5
[root@localhost ~]# docker start centos-cloudera-5
centos-cloudera-5

3.安装&启动mariadb-server

[root@centos-cloudera-5 /]#yum -y install mariadb-server
[root@centos-cloudera-5 /]# systemctl enable mariadb
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
[root@centos-cloudera-5 /]# systemctl start mariadb
[root@centos-cloudera-5 /]# systemctl status mariadb
● mariadb.service - MariaDB database server
   Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
   Active: active (running) since Tue 2017-11-07 03:24:04 UTC; 4s ago
  Process: 1620 ExecStartPost=/usr/libexec/mariadb-wait-ready $MAINPID (code=exited, status=0/SUCCESS)
  Process: 1528 ExecStartPre=/usr/libexec/mariadb-prepare-db-dir %n (code=exited, status=0/SUCCESS)
 Main PID: 1619 (mysqld_safe)
   CGroup: /docker/a582c54bb4e86567dffc8411489f7c221474860f7a63990d787083eb073a0957/system.slice/mariadb.service
           ├─1619 /bin/sh /usr/bin/mysqld_safe --basedir=/usr
           └─1780 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/var/log/mariadb/mariadb.log --pid-file=/var/run/mariadb/mariadb.pid --socket=/var/lib/mysql/mysql.sock...
           ‣ 1619 /bin/sh /usr/bin/mysqld_safe --basedir=/usr

Nov 07 03:24:00 centos-cloudera-5 systemd[1]: Starting MariaDB database server...
Nov 07 03:24:00 centos-cloudera-5 mariadb-prepare-db-dir[1528]: Initializing MariaDB database
Nov 07 03:24:01 centos-cloudera-5 mariadb-prepare-db-dir[1528]: 171107  3:24:01 [Note] /usr/libexec/mysqld (mysqld 5.5.56-MariaDB) starting as process 1599 ...
Nov 07 03:24:02 centos-cloudera-5 mariadb-prepare-db-dir[1528]: 171107  3:24:02 [Note] /usr/libexec/mysqld (mysqld 5.5.56-MariaDB) starting as process 1614 ...
Nov 07 03:24:02 centos-cloudera-5 mariadb-prepare-db-dir[1528]: PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER !
Nov 07 03:24:02 centos-cloudera-5 mysqld_safe[1619]: 171107 03:24:02 mysqld_safe Logging to '/var/log/mariadb/mariadb.log'.
Nov 07 03:24:02 centos-cloudera-5 mysqld_safe[1619]: 171107 03:24:02 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
Nov 07 03:24:04 centos-cloudera-5 systemd[1]: Started MariaDB database server.