用户密码验证方式登录:

1、查看 镜像列表:$ sudo docker images

2、开启容器:$ sudo docker run  -tid -p 22 -P 镜像名

3、进入容器:$ sudo docker exec -it 容器名 /bin/bash

4、进入容器之后进行编辑ssh文件,如果没有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配置文件:$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 root@172.17.0.2

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐