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

时间:2022-07-22
本文章向大家介绍[解决]Docker中安装Centos7后无法正常使用命令,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

问题描述

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

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

这就很烦人了,翻遍了百度,看到了这一篇解决了: https://blog.csdn.net/weixin_39726347/article/details/86981919

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

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

命令无法执行:

[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