[解决]Docker中安装Centos7后无法正常使用命令

384 阅读1分钟

问题描述

出于好奇心,在Docker中安装了Centos7系统,想搭建一个集群做测试。但是遇到了很多问题,例如下面几个。

  • 问题1:嫌弃名字太丑,想改个名字都改不了
  • 问题2:使用systemctl 命令也不能启动安装好的服务

这就很烦人了,翻遍了百度,看到了这一篇解决了:
blog.csdn.net/weixin_3972…
在这里插入图片描述

以下是个人对过程的总结:

如果没在Docker中安装Centos7的话,可以移步到:blog.csdn.net/qq_17623363…

命令无法执行:

[root@dfe2afa95f5c /]# 
[root@dfe2afa95f5c /]# hostname os2
hostname: you must be root to change the host name
[root@dfe2afa95f5c /]# 
[root@dfe2afa95f5c /]# 
[root@dfe2afa95f5c /]# systemctl start  httpd    
Failed to get D-Bus connection: Operation not permitted
[root@dfe2afa95f5c /]# 

一、退出当前的Docker中的Centos

在这里插入图片描述

二、os2就是现在无法执行命令的系统

docker ps -a
在这里插入图片描述

三、停止运行

docker stop dfe2afa95f5c
在这里插入图片描述

四、删除这个容器(注意不是删除镜像)

docker rm dfe2afa95f5c
在这里插入图片描述

五、使用特权模式run镜像

使用特权模式运行:docker run -itd --name os2 --privileged=true -p 10002:2 57fec878db54 /usr/sbin/init
我之前的命令:docker run -itd --name os1 -p 10000:22 87bd98509c5e /bin/bash

可以很明显的看出区别

在这里插入图片描述

六、测试

很OK
在这里插入图片描述