ssh远程访问docker容器
用户密码验证方式登录:
1、查看 镜像列表:$ sudo docker images
2、开启容器:$ sudo docker run  -tid -p 22 -P 镜像名
3、进入容器:$ sudo docker exec -it 容器名 /bin/bash
4、进入容器之后进行编辑ss件,如果没有ssh,需要先安装:
安装ssh-client命令:sudo
apt-get install openssh-client
安装ssh-server命令:sudo apt-get install openssh-server
安装完成以后,先启动服务:sudo /etc/init.d/ssh start
启动后,可以通过“ps -e|grep ssh”查看是否正确启动。
5、编辑ssh配置文件:docker进入容器$sudo vim/etc/ssh/sshd_config
PermitRootLogin without-password 改为 PermitRootLogin yes`
PasswordAuthentication yes 改为 PasswordAuthentication no
6、重启服务:$ sudo service ssh restart
7、设置ssh密码:passwd root
Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully
8、查看容器ip:$ ifconfig
9、可以在主服务器中链接docker:$ ssh  -p 50001 ***********.0.2
前提已安装了openssh,并且成功启动后,还无法登陆,并提示no supported authentication methods available信息时,可做以下设置:
PasswordAuthentication yes
PermitRootLogin yes

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。