您的位置:首页 > 运维架构 > Docker

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

2017-02-22 00:00 756 查看
环境: 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 中. 出现的问题:

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/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  docker iptables