用戶密碼驗證方式登錄:
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
安裝完成以后,先啟動服務(wù):sudo /etc/init.d/ssh start
啟動后,可以通過“ps -e|grep ssh”查看是否正確啟動。
5、編輯ssh配置文件:$sudo vim/etc/ssh/sshd_config
PermitRootLogin without-password 改為 PermitRootLogin yes`
7、設(shè)置ssh密碼:$ passwd root
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
8、查看容器ip:$ ifconfig
9、可以在主服務(wù)器中鏈接docker:$ ssh -p 50001 root@172.17.0.2