如何通过 SSH 连接到 Docker? [英] How to SSH into Docker?

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

问题描述

我想创建以下基础架构流程:

I'd like to create the following infrastructure flow:

如何使用 Docker 实现这一点?

How can that be achieved using Docker?

推荐答案

首先,您需要在要 ssh 进入的图像中安装 SSH 服务器.您可以为安装了 ssh 服务器的所有容器使用基本映像.然后,您只需运行每个容器,使用 -p : 将 ssh 端口(默认为 22)映射到主机端口(映像中的远程服务器).即:

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

然后,如果主机的 52022 和 53022 端口可以从外部访问,您可以使用主机(远程服务器)的 ip 直接 ssh 到容器,并在 ssh 中指定端口 -p .即:

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 到容器 1

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

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

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

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

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