我正在尝试使用这个指南:https://docs.docker.com/engine/examples/running_ssh_service/#run-a-test_sshd-container,通过获取正在运行的容器的ip地址来进行简单的SSH连接。
如果我使用以下命令SSH到容器中:
$ sudo docker inspect 4b928aca09ae
"NetworkSettings": {
"Bridge": "",
"SandboxID": "74ce28dd93a6fa6158ebc3f4ec73f1dba74ddbfc183f4ebf9cca77ced2571174",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {
"22/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "32768"
}
]
},
"SandboxKey": "/var/run/docker/netns/74ce28dd93a6",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "5927380d426ce9d5684dc17982c7f01af38d850218aa476d6ed8f457c8a39165",
"Gateway": "172.17.0.1",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "172.17.0.8",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"MacAddress": "02:42:ac:11:00:08",
"Networks": {
"bridge": {
"IPAMConfig": null,
"Links": null,
"Aliases": null,
"NetworkID": "9c02e185366bb205bded7cab97766cb0e91315a4317affedc98f299831d5ceae",
"EndpointID": "5927380d426ce9d5684dc17982c7f01af38d850218aa476d6ed8f457c8a39165",
"Gateway": "172.17.0.1",
"IPAddress": "172.17.0.8",
"IPPrefixLen": 16,
根据上述内容,我正在尝试:
$ ssh root@172.17.0.1 -p 32768
root@172.17.0.1's password:
Permission denied, please try again.
root@172.17.0.1's password:
并且:
$ ssh root@172.17.0.8 -p 32768
ssh: connect to host 172.17.0.8 port 32768: Connection refused
并且:
$ ssh root@172.17.0.8
root@172.17.0.8's password:
Permission denied, please try again.
root@172.17.0.8's password:
并且:
$ ssh root@localhost -p 32768
root@localhost's password:
Permission denied, please try again.
root@localhost's password:
使用指南中的密码:screencast
,但是它不起作用。
还验证了它正在运行:
$ sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4b928aca09ae eg_sshd "/usr/sbin/sshd -D" 3 days ago Up 33 minutes 0.0.0.0:32768->22/tcp test_sshd
如果我使用以下命令SSH到容器中:
$ sudo docker exec -i -t 4b928aca09ae /bin/bash
相反,看起来root用户没有.ssh文件夹:
root@4b928aca09ae:~# pwd
/root
root@4b928aca09ae:~# ls -la
total 20
drwx------ 2 root root 4096 Nov 30 22:01 .
drwxr-xr-x 49 root root 4096 Nov 30 22:01 ..
-rw------- 1 root root 46 Nov 30 22:01 .bash_history
-rw-r--r-- 1 root root 3106 Oct 22 2015 .bashrc
-rw-r--r-- 1 root root 148 Aug 17 2015 .profile
我也尝试运行:
root@4b928aca09ae:~# ps -A | grep sshd
1 ? 00:00:00 sshd
我不是很确定这个意思是什么。
有什么建议吗?
sudo docker exec -it 4b928aca09ae /bin/bash
。其次,您是否尝试过使用172.17.0.8而不是172.17.0.1进行ssh连接? - Gal Shaboodieg_sshd
Docker 镜像? - Gal ShaboodiFROM ubuntu:16.04
时,它可以正常工作。但是如果我使用FROM ubuntu:18.04
,连接会失败(“Permission denied, please try again.”)。也许它们的配置应该不同,但我不知道该怎么做。 - Kani