1. Install Docker and start Docker, not repeat
2. Create a directory using Dockerfile to install the SSHD service, name path customization
mkdir Sshd_centos
CD Sshd_centos
3. Edit the script file to start the sshd service
Vim run.sh content is
#!/bin/bash
/usr/sbin/sshd-d
4. Generate keys for host and Docker container communication
Ssh-keygen-t rsa-b 2048-f/etc/ssh/ssh_host_rsa_key
650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/ Images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/>650 "this.width=650;" src= "http ://s1.51cto.com/wyfs02/m01/84/59/wkiom1en2ctjllysaabjjfgyvy4725.png-wh_500x0-wm_3-wmp_4-s_2013598360.png "title = "1.png" alt= "Wkiom1en2ctjllysaabjjfgyvy4725.png-wh_50"/>
At this point into the/etc/ssh/directory can see a series of key files,
650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/ Images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/>650 "this.width=650;" src= "http ://s3.51cto.com/wyfs02/m02/84/59/wkiom1en2d3rjkhnaabk8akt0vm791.png-wh_500x0-wm_3-wmp_4-s_4016783231.png "title = "2.png" alt= "Wkiom1en2d3rjkhnaabk8akt0vm791.png-wh_50"/>
4, copy the file to the Sshd_centos directory, at this time in the Sshd_centos directory, the following./indicates the current path
Cp/etc/ssh/ssh_host_rsa_key./
Cp/etc/ssh/ssh_host_ecdsa_key./
Cp/etc/ssh/ssh_host_ed25519_key./
Cat/etc/ssh/ssh_host_rsa_key.pub > Authorized.keys
5, edit Dockerfile file Vim Dockerfile, the content is as follows
650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/ Images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/>650 "this.width=650;" src= "http ://s1.51cto.com/wyfs02/m01/84/59/wkiom1en2fozk9xiaac7znukv9a411.png-wh_500x0-wm_3-wmp_4-s_3997655008.png "title = "3.png" alt= "Wkiom1en2fozk9xiaac7znukv9a411.png-wh_50"/>
#生成的镜像以centos为基础镜像
From CentOS
#开发者信息及其他
Maintainer by test
#升级系统
RUN yum-y Update
#安装openssh-server
RUN Yum install-y openssh-server
#修改ssh_config
RUN sed-i ' s/usepam yes/usepam no/g '/etc/ssh/sshd_config
#将密钥文件复制到 the/etc/ssh directory
ADD Ssh_host_rsa_key/etc/ssh/ssh_host_rsa_key
RUN chmod 600/etc/ssh/ssh_host_rsa_key
ADD ssh_host_rsa_key.pub/etc/ssh/ssh_host_rsa_key.pub
ADD Ssh_host_ed25519_key/etc/ssh/ssh_host_ed25519_key
RUN chmod 600/etc/ssh/ssh_host_ed25519_key
ADD Ssh_host_ecdsa_key/etc/ssh/ssh_host_ecdsa_key
RUN chmod 600/etc/ssh/ssh_host_ecdsa_key
RUN mkdir-p/root/.ssh
ADD Authorized_keys/root/.ssh/authorized_keys
#将ssh服务启动脚本复制到 the/usr/local/sbin directory, and attach Execute permissions
ADD run.sh/usr/local/sbin/run.sh
RUN chmod 755/usr/local/sbin/run.sh
#变更root密码
RUN echo "root:111111" |chpasswd
#开启22端口
EXPOSE 22
#运行脚本, start the SSH service
CMD ["/usr/local/sbin/run.sh"]
Save exit to view files in the Sshd_centos directory
650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/ Images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/>
6. Generate Image files
Docker build-t Sshd:dockerfile.
Note:-T is followed by a custom container name, and finally a point. Represents the Dockerfile file in the current directory
Have information generated
650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/ Images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/>650 "this.width=650;" src= "http ://s4.51cto.com/wyfs02/m02/84/59/wkiol1en2ixjd2l2aaelaoj8qta836.png-wh_500x0-wm_3-wmp_4-s_4206275963.png "title = "5.png" alt= "Wkiol1en2ixjd2l2aaelaoj8qta836.png-wh_50"/>
finally see
650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/ Images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/>650 "this.width=650;" src= "http ://s3.51cto.com/wyfs02/m01/84/59/wkiol1en2jicrwtqaabe5iw6rv4589.png-wh_500x0-wm_3-wmp_4-s_2566451327.png "title = "6.png" alt= "wkiol1en2jicrwtqaabe5iw6rv4589.png-wh_50"/>successfully means success
Indicates that the build image was successful
Available Docker images view
650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/ Images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/>650 "this.width=650;" src= "http ://s5.51cto.com/wyfs02/m02/84/59/wkiom1en2mvckh6aaaarrztsswm485.png-wh_500x0-wm_3-wmp_4-s_612672709.png "title= "Clipboard.png" alt= "Wkiom1en2mvckh6aaaarrztsswm485.png-wh_50"/>
7. Run the image generation container
Docker run-d-P 10022:22 sshd:dockerfile
Docker PS View Container
8, in the terminal use SSH host IP 10022 can login
Another: If you cannot log in, use Docker logs container ID to view the log
This article is from the "Tea Incense" blog, please be sure to keep this source http://chinawu.blog.51cto.com/10692884/1827787
Use the Dockerfile file to create a CentOS image with the sshd service