Docker中启动mysql报错: Failed to get D-Bus connection

本文介绍了解决在Docker容器内使用systemctl启动服务时遇到的“Operation not permitted”错误的方法。一种是在运行容器时指定执行/usr/sbin/init,另一种是在Dockerfile中通过CMD指令设置。适用于CentOS 7.2环境中。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

docker版本:

[root@localhost ~]# docker versionClient:

 Version:         1.10.3

 API version:     1.22

 Package version: docker-common-1.10.3-46.el7.centos.10.x86_64

 Go version:      go1.6.3

 Git commit:      d381c64-unsupported

 Built:           Thu Aug  4 13:21:17 2016

 OS/Arch:         linux/amd64


Server:

 Version:         1.10.3

 API version:     1.22

 Package version: docker-common-1.10.3-46.el7.centos.10.x86_64

 Go version:      go1.6.3

 Git commit:      d381c64-unsupported

 Built:           Thu Aug  4 13:21:17 2016

 OS/Arch:         linux/amd64123456789101112131415161718

镜像版本


[root@b2ca5610d3da /]# cat /etc/redhat-releaseCentOS Linux release 7.2.1511 (Core) 12

    在docker中通过systemctl 启动服务的时候总是报Failed to get D-Bus connection: Operation not permitted 这样的错误提示。


[root@25d27693a24d ~]# systemctl start sshd

Failed to get D-Bus connection: Operation not permitted

    解决办法就是在docker run 的时候运行/usr/sbin/init 。比如:


[root@localhost /]# docker run -tid --name hadoopbase centos/hadoopbase:v001 /usr/sbin/init

    这样运行起来的container就可以使用systemctl来启动服务了,有的人说在CentOS7.2中解决了通过systemctl运行报错的问题,但是我在实际操作中还是遇到这样的问题。

    还有一种解决办法,就是在通过Dockerfile生成镜像文件的时候,通过CMD来执行/usr/sbin/init这条命令,即:CMD [ "/usr/sbin/init"];


本文转自 Mr_sheng 51CTO博客,原文链接:http://blog.51cto.com/sf1314/2057098


2025-06-11 11:54:40.062 | DOCKER_DEPLOY_TYPE=VM 2025-06-11 11:54:40.066 | ==> INIT /alidata/init/02init-sshd.sh 2025-06-11 11:54:40.072 | ==> EXIT CODE: 0 2025-06-11 11:54:40.072 | ==> INIT /alidata/init/fix-hosts.py 2025-06-11 11:54:40.103 | ==> EXIT CODE: 0 2025-06-11 11:54:40.103 | ==> INIT DEFAULT 2025-06-11 11:54:40.105 | Failed to get D-Bus connection: Operation not permitted 2025-06-11 11:54:40.106 | ==> INIT DONE 2025-06-11 11:54:40.106 | ==> RUN /bin/sh -c # 确保目录结构完整 2025-06-11 11:54:40.106 | mkdir -p /home/admin/canal-server/logs; 2025-06-11 11:54:40.106 | cd /home/admin/canal-server; 2025-06-11 11:54:40.106 | 2025-06-11 11:54:40.106 | # 打印关键配置 2025-06-11 11:54:40.106 | echo "===== 有效配置 ====="; 2025-06-11 11:54:40.106 | echo "canal.properties:"; 2025-06-11 11:54:40.106 | cat conf/canal.properties; 2025-06-11 11:54:40.106 | echo "instance.properties:"; 2025-06-11 11:54:40.106 | cat conf/example/instance.properties; 2025-06-11 11:54:40.106 | echo "===================="; 2025-06-11 11:54:40.106 | 2025-06-11 11:54:40.106 | # 启动 Canal 服务器 2025-06-11 11:54:40.106 | exec java ${JAVA_OPTS} -cp "conf:lib/*" \ 2025-06-11 11:54:40.106 | com.alibaba.otter.canal.deployer.CanalLauncher 2025-06-11 11:54:40.106 | 2025-06-11 11:54:40.106 | Failed to get D-Bus connection: Operation not permitted 2025-06-11 11:54:40.108 | ===== 有效配置 ===== 2025-06-11 11:54:40.108 | canal.properties: 2025-06-11 11:54:40.110 | canal.id = 1001 2025-06-11 11:54:40.110 | canal.port = 11111 2025-06-11 11:54:40.110 | canal.destinations = example 2025-06-11 11:54:40.110 | canal.zookeeper.switch = false 2025-06-11 11:54:40.110 | canal.instance.global.spring.xml = classpath:spring/default-instance.xmlinstance.properties: 2025-06-11 11:54:40.113 | canal.instance.mysql.slaveId = 1234 2025-06-11 11:54:40.113 | canal.instance.master.address = host.docker.internal:3306 2025-06-11 11:54:40.113 | canal.instance.dbUsername = canal 2025-06-11 11:54:40.113 | canal.instance.dbPassword = tx123456 2025-06-11 11:54:40.113 | canal.instance.connectionCharset = UTF-8 2025-06-11 11:54:40.113 | canal.instance.filter.regex = .*\\..*==================== 2025-06-11 11:54:40.323 | 03:54:40,213 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback-test.xml] 2025-06-11 11:54:40.323 | 03:54:40,213 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.groovy] 2025-06-11 11:54:40.323 | 03:54:40,214 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [logback.xml] at [file:/home/admin/canal-server/conf/logback.xml] 2025-06-11 11:54:40.324 | 03:54:40,324 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender] 2025-06-11 11:54:40.330 | 03:54:40,330 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [STDOUT] 2025-06-11 11:54:40.337 | 03:54:40,337 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property 2025-06-11 11:54:40.372 | 03:54:40,372 |-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level of ROOT logger to DEBUG 2025-06-11 11:54:40.372 | 03:54:40,372 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [STDOUT] to Logger[ROOT] 2025-06-11 11:54:40.372 | 03:54:40,372 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration. 2025-06-11 11:54:40.374 | 03:54:40,373 |-INFO in ch.qos.logback.classic.joran.JoranConfigurator@47fd17e3 - Registering current configuration as safe fallback point 2025-06-11 11:54:40.410 | 2025-06-11 03:54:40.406 [main] INFO c.a.o.canal.deployer.CanalLauncher - ## set default uncaught exception handler 2025-06-11 11:54:40.410 | 2025-06-11 03:54:40.410 [main] INFO c.a.o.canal.deployer.CanalLauncher - ## load canal configurations 2025-06-11 11:54:40.434 | 2025-06-11 03:54:40.433 [main] ERROR c.a.o.canal.deployer.CanalLauncher - ## Something goes wrong when starting up the canal Server: 2025-06-11 11:54:40.434 | java.lang.NullPointerException: null 2025-06-11 11:54:40.434 | at com.alibaba.otter.canal.deployer.CanalStarter.start(CanalStarter.java:69) 2025-06-11 11:54:40.434 | at com.alibaba.otter.canal.deployer.CanalLauncher.main(CanalLauncher.java:124)
06-13
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值