简体   繁体   English

使用 ssh 连接到 docker 容器时出错

[英]getting error when using ssh to connect to a docker container

I got a container that has openssh installed and can be connnected via the command ssh 172.17.0.2 .我有一个安装了 openssh 的容器,可以通过命令ssh 172.17.0.2进行连接。

Now I want to get a port (say 32769) on the host side, and map the port 22 (of docker container) to it, the reason for doing that is I want to get the ssh 127.0.0.1 -p 32769 works on localhost, I got the errors as : ssh_exchange_identification: read: Connection reset by peer .现在我想在主机端获取一个端口(比如 32769),并将端口 22(docker 容器)映射到它,这样做的原因是我想让ssh 127.0.0.1 -p 32769在本地主机上工作,我得到的错误是: ssh_exchange_identification: read: Connection reset by peer The port mapping is showing normally on docker engine: 0.0.0.0:32769->22/tcp .端口映射在 docker 引擎上正常显示: 0.0.0.0:32769->22/tcp

Can somebody help me with that?有人可以帮我吗? Much appreciated!非常感激!

Check that the SSH daemon is running in your container first (through a docker exec or docker attach session):首先检查 SSH 守护进程是否在您的容器中运行(通过docker execdocker attach会话):

service ssh status
# or
service sshd status

Make sure you have the right IP address确保您拥有正确的 IP 地址

sudo docker inspect -f "{{ .NetworkSettings.IPAddress }}" Container_Name

Use the right SSH URL:使用正确的 SSH URL:

ssh root@172.17.0.2

See more in " How to SSH into a Running Docker Container and Run Commands " from Sofija Simic.在 Sofija Simic 的“如何通过 SSH 连接到正在运行的 Docker 容器并运行命令”中查看更多信息。

Using a docker run -p 32769:22 is in your case a good idea.在您的情况下,使用docker run -p 32769:22是个好主意。


The OP mentions in the discussion an issue with docker proxy: OP 在讨论中提到了 docker 代理的问题:

The docker-proxy was not getting eth0 of the container as -container-ip . docker-proxy 没有将容器的 eth0 作为-container-ip
Here is what I've got这是我所拥有的

/usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 32785 \\ -container-ip 172.21.1.2 -container-port 22

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM