标签:
这里测试tomcat镜像安装ssh服务
1.启动镜像
[root@wls12c docker]$ docker run -d tomcat:centos 844bdde121a03174f3abd226a9ef286938b6ea4a1fbd2659961b1e8542ca3ccd [root@wls12c docker]$ docker exec -it 844 /bin/bash [root@844bdde121a0 /]#
2.安装ssh服务
[root@844bdde121a0 /]# yum -y install openssh-server
3.要正常启动服务必须存在"/var/run/sshd"目录,创建它
[root@844bdde121a0 /]# mkdir /var/run/sshd
4.启动sshd服务
[root@844bdde121a0 /]# /usr/sbin/sshd -D & [1] 118
5.查看启动端口
[root@844bdde121a0 /]# lsof -i:22 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME sshd 118 root 3u IPv4 207270 0t0 TCP *:ssh (LISTEN) sshd 118 root 4u IPv6 207272 0t0 TCP *:ssh (LISTEN)
6.将宿主机的公钥导入到/root/.ssh/authorized_keys目录下
[root@844bdde121a0 /]# mkdir root/.ssh [root@844bdde121a0 /]# vi /root/.ssh/authorized_keys ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEApcDYVQ7JdPYwyWzdna/T2Z41wRypL+zJQt0zA3hbf6kZMI6gmPTsDl1t37swyj xtlLK1Saiq5rE12gL7qfIsfR5Vwunmj4uKXfNBjSh472GXJOpHPB+Wz28Xf53Yc0x589YSdkE3lsJ8EFpdQntuETj4q47905ji ZEjaukAp+uy6qNLTXaaTLUzod4Y8t9h5KbqYKfE+wfnVrfpSJhzVTLPSJ7NiBtQTccMCQkxeNYgtaBPLh7I3OmA1hsoDuRbDcX 9RivGLkrdct0WT7W/IFPhdF2vHZ6QRTvYw3B6//RYFK7/nkRJglvsERyPJdUCU340xNiplCepR3yaxSMSmpw== root@wls12c
7.编辑ssh服务可执行文件
[root@844bdde121a0 /]# vi run.sh #/bin/bash /usr/sbin/sshd -D &
8.给run.sh可执行权限
chmod 755 /run.sh
9.查看是否生成了主机密钥,没有则生成
[root@91f4be81e455 ssh]# rm -rf ssh*key [root@91f4be81e455 ssh]# ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key [root@91f4be81e455 ssh]# ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key [root@91f4be81e455 ssh]# ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key
10.保存镜像
docker commit 91f tomcat-sshd
11.运行镜像
docker run --name tomcat--ssh -d -p 100022:22 -p 8090:8080 3364 /run.sh
12.可以在宿主机和其它机器进行连接了
root@wls12c ~]$ ssh 192.168.0.80 -p 10022 The authenticity of host ‘[192.168.0.80]:2222 ([192.168.0.80]:2222)‘ can‘t be established. RSA key fingerprint is 03:15:c4:ab:97:ea:7e:58:3b:3d:22:42:db:50:a3:46. Are you sure you want to continue connecting (yes/no)? yesy Warning: Permanently added ‘[192.168.0.80]:2222‘ (RSA) to the list of known hosts. [root@04cbe75bfef9 ~]#
标签:
原文地址:http://www.cnblogs.com/zydev/p/5817804.html