Docker中开启sshd服务

    1. ssh服务安装
      • 安装ssh服务

        #yum install openssh-server -y

      • 安装passwd(修改密码需要)

        #yum install passwd -y

      • 修改sshd_config配置文件

        UsePAM yes改成UsePAM no

      • 关闭主机selinux

        当使用passwd修改容器中root密码的时候,会报错:
        passwd: system_u:system_r:initrc_t:s0 is not authorized to change the password of root
        这时候,需要关闭主机selinux。

    2. 开机自起
      在/root目录下创建run.sh脚本,添加如下内容:
       #!/bin/bash
       service sshd restart
       while :
       do
       sleep 10
       done

      其实开机自起可以用CMD的,但是暂时不会。。。就统一用脚本执行的方式防止退出,感觉可调控行蛮好的。

    3. 保存修改
      • 查看正在运行的容器ID

        #docker ps

      • commit修改的容器ID,保存为centos6.5,tag为sshd

        #docker commit ID centos6.5:sshd

    4. 开启服务

      #docker run -d -p 22:22 -t centos6.5:sshd /root/run.sh
      以后台模式运行容器,且把容器的22端口映射到主机的22端口
      这样,就可以从外网通过ssh连接到容器了。

    5.  

posted @ 2015-01-14 10:37  samu  阅读(572)  评论(0编辑  收藏  举报