最具影响力的数字化技术在线社区

168大数据

 找回密码
 立即注册

QQ登录

只需一步,快速开始

1 2 3 4 5
打印 上一主题 下一主题
开启左侧

Docker 中使用 CentOS7 systemd 报错解决

[复制链接]
跳转到指定楼层
楼主
发表于 2018-1-23 15:17:49 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多数据大咖,获取更多知识干货,轻松玩转大数据

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
在docker中使用 CentOS7 官方镜像的时候,使用Systemd 的话会报错:

➜  ~ docker run -it centos:7 /bin/bash
[root@ead8524a303e /]# systemctl list-units
Failed to get D-Bus connection: Operation not permitted
[root@ead8524a303e /]# exit

# 加上权限参数也不行
➜  ~ docker run -it --privileged centos:7 /bin/bash
[root@fd105049c04c /]# systemctl list-units
Failed to get D-Bus connection: Operation not permitted
查了一下 官方的文档说明https://hub.docker.com/_/centos/,需要使用/usr/sbin/init 初始化才能使用Systemd服务,因为好多服务没启动。

测试了一下,分享一下我的Dockerfile:

FROM centos:7
MAINTAINER "sandy" <sandy@hainiubl.com>
ENV container docker
RUN echo 'root:hainiu' | chpasswd

RUN (cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i == systemd-tmpfiles-setup.service ] || rm -f $i; done)
RUN rm -f /etc/systemd/system/*.wants/* \
rm -f /lib/systemd/system/local-fs.target.wants/*; \
rm -f /lib/systemd/system/sockets.target.wants/*udev*; \
rm -f /lib/systemd/system/sockets.target.wants/*initctl*; \
rm -f /lib/systemd/system/basic.target.wants/*;\
rm -f /lib/systemd/system/anaconda.target.wants/*;
CMD ["/usr/sbin/init"]
build的一下:

docker build --rm -t hainiubl/centos7 .
再运行一下试试:

~ docker run -it --privileged --hostname master.hadoop hainiubl/centos7

systemd 219 running in system mode. (+PAM +AUDIT +SELINUX +IMA -APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ -LZ4 -SECCOMP +BLKID +ELFUTILS +KMOD +IDN)
Detected virtualization docker.
Detected architecture x86-64.

Welcome to CentOS Linux 7 (Core)!

Set hostname to <master.hadoop>.
Initializing machine ID from random generator.
Failed to install release agent, ignoring: No such file or directory
[  OK  ] Reached target Paths.
[  OK  ] Reached target Swap.
[  OK  ] Reached target Local File Systems.
[  OK  ] Created slice Root Slice.
[  OK  ] Created slice System Slice.
[  OK  ] Created slice User and Session Slice.
[  OK  ] Reached target Slices.
[  OK  ] Listening on Journal Socket.
         Starting Create Volatile Files and Directories...
[  OK  ] Listening on Delayed Shutdown Socket.
         Starting Journal Service...
[  OK  ] Started Create Volatile Files and Directories.
[ INFO ] Update UTMP about System Boot/Shutdown is not active.
[DEPEND] Dependency failed for Update UTMP about System Runlevel Changes.
Job systemd-update-utmp-runlevel.service/start failed with result 'dependency'.
[  OK  ] Started Journal Service.
[  OK  ] Reached target System Initialization.
[  OK  ] Reached target Timers.
[  OK  ] Listening on D-Bus System Message Bus Socket.
[  OK  ] Reached target Sockets.
[  OK  ] Reached target Basic System.
         Starting Permit User Sessions...
[  OK  ] Started D-Bus System Message Bus.
         Starting D-Bus System Message Bus...
         Starting Login Service...
[  OK  ] Started Permit User Sessions.
         Starting Cleanup of Temporary Directories...
[  OK  ] Started Console Getty.
         Starting Console Getty...
[  OK  ] Reached target Login Prompts.
[  OK  ] Started Login Service.
[  OK  ] Reached target Multi-User System.
[  OK  ] Started Cleanup of Temporary Directories.

CentOS Linux 7 (Core)
Kernel 4.4.27-moby on an x86_64

master login: root
Password:
[root@master ~]#
[root@master ~]# systemctl list-units
UNIT                      LOAD   ACTIVE     SUB       DESCRIPTION
dev-vda2.device           loaded activating tentative /dev/vda2
-.mount                   loaded active     mounted   /
dev-mqueue.mount          loaded active     mounted   POSIX Message Queue File S
etc-hostname.mount        loaded active     mounted   /etc/hostname
etc-hosts.mount           loaded active     mounted   /etc/hosts
etc-resolv.conf.mount     loaded active     mounted   /etc/resolv.conf
systemd-ask-password-wall.path loaded active     waiting   Forward Password Requ
ests

......
这样就可以了,很多情况下使用docker其实用不到Systemd,docker推崇单服务容器。

版权声明:原创作品,允许转载,转载时务必以超链接的形式表明出处和作者信息。否则将追究法律责任。来自海牛部落-海牛博士,http://hainiubl.com/topics/1
楼主热帖
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 转播转播 分享分享 分享淘帖 赞 踩

168大数据 - 论坛版权1.本主题所有言论和图片纯属网友个人见解,与本站立场无关
2.本站所有主题由网友自行投稿发布。若为首发或独家,该帖子作者与168大数据享有帖子相关版权。
3.其他单位或个人使用、转载或引用本文时必须同时征得该帖子作者和168大数据的同意,并添加本文出处。
4.本站所收集的部分公开资料来源于网络,转载目的在于传递价值及用于交流学习,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。
5.任何通过此网页连接而得到的资讯、产品及服务,本站概不负责,亦不负任何法律责任。
6.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源,若标注有误或遗漏而侵犯到任何版权问题,请尽快告知,本站将及时删除。
7.168大数据管理员和版主有权不事先通知发贴者而删除本文。

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

站长推荐上一条 /1 下一条

关于我们|小黑屋|Archiver|168大数据 ( 京ICP备14035423号|申请友情链接

GMT+8, 2024-5-9 20:57

Powered by BI168大数据社区

© 2012-2014 168大数据

快速回复 返回顶部 返回列表