如何SSH到Docker? [英] How to SSH into Docker?

查看:287
本文介绍了如何SSH到Docker?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建以下基础设施流程:





如何使用Docker实现?

解决方案

首先,您需要在希望ssh进入的映像中安装SSH服务器。您可以使用安装了ssh服务器的所有容器的基本映像。
那么你只需要使用 -p< hostPort>:< hostPort>来运行每个容器将ssh端口(默认22)映射到主机的端口(映像中的远程服务器) containerPort> 。即:

  docker run -p 52022:22 container1 
docker run -p 53022:22 container2
然后,如果主机的端口52022和53022可以从外部访问,则可以使用ip的主机(远程服务器)使用 -p< port> 指定ssh中的端口。即:



ssh -p 52022 myuser @ RemoteServer - > SSH到container1



ssh -p 53022 myuser @ RemoteServer - > SSH到container2


I'd like to create the following infrastructure flow:

How can that be achieved using Docker?

解决方案

Firstly you need to install a SSH server in the images you wish to ssh-into. You can use a base image for all your container with the ssh server installed. Then you only have to run each container mapping the ssh port (default 22) to one to the host's ports (Remote Server in your image), using -p <hostPort>:<containerPort>. i.e:

docker run -p 52022:22 container1 
docker run -p 53022:22 container2

Then, if ports 52022 and 53022 of host's are accessible from outside, you can directly ssh to the containers using the ip of the host (Remote Server) specifying the port in ssh with -p <port>. I.e.:

ssh -p 52022 myuser@RemoteServer --> SSH to container1

ssh -p 53022 myuser@RemoteServer --> SSH to container2

这篇关于如何SSH到Docker?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆