从docker下载默认的CentOS镜像没有开启systemd,执行systemctl命令会显示“Failed to get D-Bus connection: Operation not permitted”错误 ,如果docker创建centos7的容器涉及到systemctl服务操作,或者需要实现容器开机后自动启动服务功能。需要调整镜像并且修改镜像启动方式。
1. docker拉取centos7镜像
docker pull centos:centos7.9.2009
2. 编写dockerfile文件
vi centos.dockerfile
添加以下内容上去
FROM centos:centos7.9.2009
ENV container docker
RUN (cd /lib/systemd