azure - 通过 SSH 连接到 Docker 容器的 Azure 应用服务

标签 azure docker ssh azure-devops azure-web-app-service

问题 1

我正在寻找一种通过 SSH 连接到正在运行的容器或适用于 Docker 容器 (Linux) 的 Azure 应用服务中的托管 VM 的方法。我读过doc for enabling SSH when configuring a custom containerthis question 。但是,这两个链接都要求我安装 openssh在我的图像中:

# Install OpenSSH and set the password for root to "Docker!". In this example, "apk add" is the install instruction for an Alpine Linux-based image.
RUN apk add openssh \
     && echo "root:Docker!" | chpasswd 

# Copy the sshd_config file to the /etc/ssh/ directory
COPY sshd_config /etc/ssh/

# Open port 2222 for SSH access
EXPOSE 80 2222

我不想将其用于我的图像,因为它可能会带来安全问题。我可以直接连接到托管容器的虚拟机并执行类似 docker exec -it <container name> /bin/bash 的操作吗? ?

问题 2

如果我安装 openssh并以这种方式 SSH 到容器中,如果我有自动扩展并且运行多个实例/容器,会发生什么情况,我要 SSH 到哪个容器?<​​/p>

最佳答案

Can I connect directly to the VM that hosts my containers and do something like docker exec -it /bin/bash?

当然不是。您可以直接连接到容器的主机。实际上,主机是应用服务托管的应用服务计划。我想您知道应用服务计划无法连接到。

If I do install openssh and SSH into the container this way, what happens if I have auto-scaling and multiple instances/containers running, which container am I SSHing into?

当您为容器启用 SSH 时,您将 ssh 进入容器,而不是服务计划实例,因此,如果您扩展服务计划,不会对您 ssh 进入容器产生任何影响。如果您为应用服务中的多个容器启用 SSH,则可以通过 ssh 访问所有容器。但有一件事你需要知道。您首先 ssh 到的是前端,您可以通过端口 2222 的服务名称 ssh 到其他前端。例如,docker-compose.yml 如下所示:

version: '3.3'

services:
  frontend:
    image: xxxxxx
    ...

  backend:
    image: xxxxxx
    ...

然后您首先 ssh 进入前端,也可以在前端容器内 ssh 进入后端:

ssh backend -p 2222

关于azure - 通过 SSH 连接到 Docker 容器的 Azure 应用服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67731411/

相关文章:

node.js - 如何在Azure上运行nodejs、express js项目的启动命令?

azure - 无法在 azure ARM VPN 连接中通过 Rasdial 进行连接

c# - Azure 上的 Server.MapPath 访问被拒绝

docker couchdb 数据量不保存到本地文件系统

asp.net - 如何从 ASP.NET Core 项目中删除 docker 支持?

git - 递归 git clone 期间的用户名错误

ssh - Rsync 相当于 scp -3

azure - 读取 CSV 时,是否可以选择从第 2 行或以下行开始?

bash - Docker启动容器进程导致 “exec:\” arg\“: executable file not found in $PATH”:未知。

python - 嵌套结构连接