使用dockerfile创建支持ssh远程的镜像
2016-01-11 09:42
1101 查看
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本文出自 “黑夜路人” 博客,请务必保留此出处/article/4422515.html
[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本文出自 “黑夜路人” 博客,请务必保留此出处/article/4422515.html
相关文章推荐
- Docker系列之――lxc虚拟化快速入门
- 如何在Win7系统中安装Docker客户端
- 【原创】基于Docker的CaaS容器云平台架构设计及市场分析
- 虚拟化技术docker
- 如何利用 Docker 环境加速 Android 应用的构建
- Docker简明教程(转)
- Docker简介(转)
- docker入门与hadoop
- 【原创】Docker容器及Spring Boot微服务应用
- 【原创译文】基于Docker和Rancher的超融合容器云架构
- Docker:私有仓库的搭建
- Docker:最简实践笔记
- 什么是 Docker?
- docker 相关文章
- .NET开发者启程Docker之路
- docker的使用总结
- 使用dockerfile创建支持ssh远程的镜像
- 加速DockerImage下载方法
- Docker常见问题
- docker registry v2 nginx 安全访问控制