docker 搭建centos6.5 ssh 服务出现的问题

环境: host Machine: centos7 x86-64
docker : 1.13.1
image name : mycentos6.5

一、 准备工作中出现的问题:

docker 启动centos6.5 创建 一个容器 :
docker run -it --name centos6.5 mycentos6.5Image /bin/bash
这样 则进入 centos6.5 中. 出现的问题:

  1. iptables 无法使用: eg: #iptables -L 出现类似的问题(来源于其他):

Table: filter FATAL: Could not load /lib/modules/2.6.32-358.el6.x86_64/modules.dep: No such file or directory iptables v1.4.7: can't initialize iptables table `filter': Permission denied (you must be root) Perhaps iptables or your kernel needs to be upgraded. Table: nat FATAL: Could not load /lib/modules/2.6.32-358.el6.x86_64/modules.dep: No such file or directory iptables v1.4.7: can't initialize iptables table ‘nat': Permission denied (you must be root) Perhaps iptables or your kernel needs to be upgraded

 solve:  
  由于容器创建容器为了安全, 将访问设备的权限默认禁止, 因此 我们使用iptables 或者mount 时 出现不可访问的现象, **解决**: 在docker创建容器时, 添加`--priviliged` 开放所有权限,像操作实体机一样,当然也有其他方式,指定设备的访问权限,具体可以看看--cap-add。 添加后的代码:  
`docker  run -it --privileged --name centos6.5  mycentos6.5  /bin/bash`  
重新进入系统内, 就可以使用iptables了。  
2 . 在想要给系统重新设置密码时:  
 paawd: 出现问题:   
  `:s0 is not authorized to change the password of root`(来源于其他): 这可能是由于selinux的问题(这个也不太懂 ,自行google  ^ . ^):大致是由于在容器内创建用户名或者密码时,由于selinux所设置的最小权限原则导致无法顺利执行: **解决方法**:
     1. 进入物理机 : #  sestatus    
                  `SELinux status:      enabled`  
      2. 修改 /etc/selinux/config  
                  `SELINUX=disabled`  
      3. 保存并退出
      4. 重启
      5. 执行: #getenforce  
             `Disabled`  
    再次进入则就可以使用passwd 修改密码了.
   **详情可以在下面链接中查看:** 
 

二: 搭建sshd 服务:      

         a.) 创建容器并运行:   
                ```   dokcer run -it --privileged --name centos6.5 -p hostIp:hostPort:dockerPort                          mycentos6.5Image   /bin/bash   ```  
       b.) 关闭iptables : (保证端口能够使用,不会被限制) 
                ```   #service iptables stop    ```  
       c.) 重新键入密码:  
               ```   #passwd   ```   ( eg : abc123)   
       d.) 启动sshd 服务:   
                 ```   #service sshd start   ``` 
 三: ssh 远程访问: 
         linux : 
         ```#ssh -p hostPort  dockerUsername(eg: root)@hostIp```  
           ----> Enter:   ---> input passwd of dockerUsername(as above:abc123) .  
        windows:  使用putty  填入对应的hostip 和hostport 点击登陆 然后输入用户名的密码即可。
     

note:  若contain 重新启动, 需要重新启动sshd 服务,  或者直接将 启动sshd服务设置成开机启动。  
                
参考链接:  
    selinux关闭: http://linuxys.blogspot.com/2014/12/solved-lxc-not-authorized-to-change.html   
   docker privileged的介绍: http://ikarishinjieva.github.io/tachikoma-blog/post/2014-07-10-docker-some-error/

转载于:https://my.oschina.net/longtian/blog/843809

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值