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

使用dockerfile创建支持ssh远程的镜像

2016-01-08 10:17 1051 查看
1、创建相关目录[root@linux-node1~]# mkdir /docker/sshd –p2、编写dockerfile[root@linux-node1 sshd]# vim Dockerfile# This is a dockerfile# Version 1# By Kevin# Base imageFrom centos# MaintainerMAINTAINER Kevin kevinhao.blog.51cto.com # Commands # Install and Configure sshdRUN yum install -y openssh-serverRUN sed -i 's/UsePAM yes/UsePAM no/g' /etc/ssh/sshd_config # Add the user kevin and set it's password for kevinRUN useradd kevinRUN echo "kevin:kevin"|chpasswdRUN echo "kevin ALL=(ALL) ALL">>/etc/sudoers # Generate a keypairRUN ssh-keygen -tdsa -f /etc/ssh/ssh_host_dsa_keyRUN ssh-keygen -trsa -f /etc/ssh/ssh_host_rsa_key #Star the sshd service and expose the port 22RUN mkdir /var/run/sshdEXPOSE 22CMD ["/usr/sbin/sshd","-D"][root@linux-node1sshd]# cd3、创建镜像[root@linux-node1~]# docker build -t kevin/sshd /docker/sshd/4、查看镜像[root@linux-node1~]# docker images|grep sshdkevin/sshd latest d0b5016b8463 7 minutes ago 259.1 MB5、启动测试[root@linux-node1~]# docker run --name sshdtest -d -P kevin/sshd6、ssh远程6.1、查看端口映射
[root@linux-node1~]# docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESda430c0d9f1b kevin/sshd "/usr/sbin/sshd -D" 38 seconds ago Up 37 seconds 0.0.0.0:32769->22/tcp sshdtest6.2使用ssh远程登录
[root@linux-node1~]# ssh kevin@192.168.56.3 -p32769The authenticity of host '[192.168.56.3]:32769 ([192.168.56.3]:32769)' can't be established.RSA key fingerprintis d4:52:73:db:4c:85:ff:d5:6a:78:23:ff:52:67:01:2f.Are you sure you want to continue connecting (yes/no)? yesWarning:Permanently added '[192.168.56.3]:32769' (RSA) to the list of known hosts.kevin@192.168.56.3'spassword: [kevin@da430c0d9f1b~]$ pwd/home/kevin成功ssh远程到容器[kevin@da430c0d9f1b~]$ exitlogoutConnection to192.168.56.3 closed.此外还可以使用 ssh kevin@<container_ip>
Linux运维开发群:298324302
北京linux运维求职招聘群:153677549
本文出自 “长街听风人” 博客,请务必保留此出处http://kevinhao.blog.51cto.com/5204735/1732782
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: