简体   繁体   English

连接被拒绝 | Docker & ssh

[英]Connection refused | Docker & ssh

I'm trying to connect to an ssh server from a docker container lifted by docker-compose.我正在尝试从由 docker-compose 提升的 docker 容器连接到 ssh 服务器。

On my localhost, I have enabled the port to use with "ufw allow 4222" , I have placed port 4222 in my docker-compose.yml file.在我的本地主机上,我已启用端口以使用"ufw allow 4222" ,我已将端口 4222 放在我的 docker-compose.yml 文件中。

I have also added the public key of my localhost to the container and to the authorized keys of the server, the problem is that it keeps failing me, someone knows that more I can check or take into account?我还将本地主机的公钥添加到容器和服务器的授权密钥中,问题是它一直让我失败,有人知道我可以检查或考虑更多吗? thank you.谢谢你。

docker-compose.yml docker-compose.yml

version: '3.9'

services:
      hermes:
              depends_on:
                      - mongodb
              build:
                      context: ./hermes-app/
              container_name: hermes
              tty: true
              ports:
                      - "5000:5000"
                      - "4222"
              environment:
                           - SLACK_CLIENT_ID=${SLACK_CLIENT_ID}
                           - SLACK_CLIENT_SECRET=${SLACK_CLIENT_SECRET}
                           - SLACK_SIGNING_SECRET=${SLACK_SIGNING_SECRET}
                           - SLACK_VERIFICATION_TOKEN=${SLACK_VERIFICATION_TOKEN}
                           - SSH_HOST=${SSH_HOST}
                           - SSH_USER=${SSH_USER}
                           - SSH_PORT=${SSH_PORT}
              networks:
                      - netrmes

Error:错误:

root@6d55aa960f46:/hermes-app# ssh root@my_server -p 4222
ssh: connect to host my_server port 4222: Connection refused

So you try to ssh from the container to your host system.因此,您尝试将 ssh 从容器传输到您的主机系统。 The container knows nothing about my_server if it is not in netrmes network.如果容器不在 netrmes 网络中,则容器对 my_server 一无所知。 You could use host network and then您可以使用host网络,然后

ssh root@localhost -p 4222

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

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