创建带sshd服务的docker image

王朝学院·作者佚名  2016-05-27
窄屏简体版  字體: 小  |  中  |  大  |  超大  

创建带sshd服务的docker image参考:https://docs.docker.com/examples/running_ssh_service/

1.创建一个空目录用于存放Dockerfile

mkdir -p/home/thm/docker/test/new_image

vim Dockerfile

Dockerfile的内容为:

FROM tanghuimin0713/Ubuntu_amd64:14.04 RUN apt-get update RUN apt-get install -y openssh-server #RUN mkdir /var/run/sshd RUN sed -i 's/^PermitRootLogin/#PermitRootLogin/' /etc/ssh/sshd_config RUN echo "PermitRootLogin yes" >> /etc/ssh/sshd_config RUN echo "root:root" | chpasswd EXPOSE 22

2. build a image

docker build -t tanghuimin0713/ubuntu_amd64_ssh .

3. run a container

docker run -d -p 2222:22 tanghuimin0713/ubuntu_amd64_ssh /usr/sbin/sshd -D

4. 主机下ssh登陆docker容器

ssh root@localhost -p 2222

密码为:root

root@ubuntu:/home/thm/docker/test/new_image# ssh root@localhost -p 2222The authenticity of host '[localhost]:2222 ([127.0.0.1]:2222)' can't be established.ECDSA key fingerPRint is bd:41:3f:e4:e3:bd:b4:46:54:fe:1b:46:eb:60:f3:73.Are you sure you want to continue connecting (yes/no)? yesWarning: Permanently added '[localhost]:2222' (ECDSA) to the list of known hosts.root@localhost's passWord: Welcome to Ubuntu 14.04 LTS (GNU/linux 3.13.0-32-generic x86_64) * Documentation: https://help.ubuntu.com/The programs included with the Ubuntu system are free software;the exact distribution terms for each program are described in theindividual files in /usr/share/doc/*/copyright.Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted byapplicable law.root@db36812760ac:~#

成功。

若在ssh登陆时提示:

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!Someone could be eavesdropping on you right now (man-in-the-middle attack)!It is also possible that a host key has just been changed.The fingerprint for the ECDSA key sent by the remote host isbd:41:3f:e4:e3:bd:b4:46:54:fe:1b:46:eb:60:f3:73.Please contact your system administrator.Add correct host key in /root/.ssh/known_hosts to get rid of this message.Offending ECDSA key in /root/.ssh/known_hosts:5 remove with: ssh-keygen -f "/root/.ssh/known_hosts" -R 172.17.0.2ECDSA host key for 172.17.0.2 has changed and you have requested strict checking.Host key verification failed.

rm $HOME/.ssh/known_hosts即可。

 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
© 2005- 王朝網路 版權所有 導航