简体   繁体   English

如何通过 ssh 进入 Azure 上的“Web App On Linux”docker 容器?

[英]How can I ssh into “Web App On Linux” docker container on Azure?

How can I ssh into the container with the new "Web App On Linux" service?如何使用新的“Web App On Linux”服务通过 ssh 进入容器?

It is currently in preview mode, I'm not sure that it is not possible yet or I have overseen the settings.它目前处于预览模式,我不确定这是不可能的,或者我已经监督了设置。

Here is an example that I got working with ssh together with a asp.net core app in linux container:这是我在 linux 容器中将 ssh 与 asp.net 核心应用程序一起使用的示例:

Dockerfile文件

#base image
FROM mcr.microsoft.com/dotnet/core/aspnet:3.0-buster-slim AS base

#ssh
ENV SSH_PASSWD "root:Docker!"
RUN apt-get update \
        && apt-get install -y --no-install-recommends dialog \
        && apt-get update \
  && apt-get install -y --no-install-recommends openssh-server \
  && echo "$SSH_PASSWD" | chpasswd 

COPY MyApp/sshd_config /etc/ssh/
COPY MyApp/init.sh /usr/local/bin/

WORKDIR /app
EXPOSE 80 443 2222

FROM mcr.microsoft.com/dotnet/core/sdk:3.0-buster AS build
WORKDIR /src
COPY ["MyApp/MyApp.csproj", "MyApp/"]
RUN dotnet restore "MyApp/MyApp.csproj"
COPY . .
WORKDIR "/src/MyApp"
RUN dotnet build "MyApp.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "MyApp.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
    
ENTRYPOINT ["bash","init.sh"]

init.sh in root folder of .net core project .net core 项目根目录下的init.sh

service ssh start
dotnet MyApp.dll

sshd_config in root folder of .net core project .net core 项目根目录下的sshd_config

#
# /etc/ssh/sshd_config
#

Port            2222
ListenAddress       0.0.0.0
LoginGraceTime      180
X11Forwarding       yes
Ciphers                 aes128-cbc,3des-cbc,aes256-cbc
MACs                    hmac-sha1,hmac-sha1-96
StrictModes         yes
SyslogFacility      DAEMON
PrintMotd       no
IgnoreRhosts        no
#deprecated option 
#RhostsAuthentication   no
RhostsRSAAuthentication yes
RSAAuthentication   no 
PasswordAuthentication  yes
PermitEmptyPasswords    no
PermitRootLogin     yes

在此处输入图片说明

For now, It is not possible.目前,这是不可能的。 Please refer to this feedback .请参考此反馈

Update on 2017-6-8 2017-6-8 更新

Now, it is possible, please refer to SSH support for Azure Web App on Linux .现在,可以了,请参阅Linux 上 Azure Web App 的 SSH 支持

As of today (4/1/2019) it is possible according to this doc: Connect to Web App for Containers using .截至今天(2019 年 4 月 1 日),根据此文档可以使用: Connect to Web App for Containers using . It's kind of hacking but it does the trick.这是一种黑客行为,但它确实有效。

Not an April fool's joke.不是愚人节玩笑。

For anyone having issues with @ sgedda 's answer as @ Manish Jain is having, try using:对于@ sgedda的回答有问题的任何人,如@ Manish Jain所拥有的,请尝试使用:

ENTRYPOINT ["bash", "init.sh"]

It worked for me.它对我有用。

I don't believe you can.我不相信你可以。 But depending on what you want to do (eg view log files), you could use bash from Kudu (via Advanced Tools > Debug console > Bash)但是根据您想要做什么(例如查看日志文件),您可以使用 Kudu 中的 bash(通过高级工具 > 调试控制台 > Bash)

That said, Web App On Linux is in preview - so SSH may be possible in the future!也就是说,Linux 上的 Web 应用程序处于预览阶段 - 所以 SSH 可能在未来成为可能!

I found @Sgedda's reply to be very helpful.我发现@Sgedda 的回复非常有帮助。 I followed his example to the letter, but I kept getting this error exec user process caused "exec format error"我按照他的例子来信,但我一直收到这个错误exec user process caused "exec format error"

In addition to implementing his example, I also did the following除了实现他的例子,我还做了以下

  1. Added #!/bin/bash as the 1st line of the init.sh file.添加#!/bin/bash作为init.sh文件的第一行。 It's important that there is NOTHING in front of it nor at the end of that line AND that it's the 1st line in the file.重要的是,它的前面或该行的末尾都没有任何内容,并且它是文件中的第一行。 service ssh start is line 2. service ssh start是第 2 行。
  2. Changed the encoding of the init.sh and sshd_config files to ISO 8859-15 using VS Code使用 VS Code 将init.shsshd_config文件的编码更改为ISO 8859-15 在此处输入图片说明
  3. Changed the line endings of the init.sh and sshd_config files to LF using VS Code使用 VS Code 将init.shsshd_config文件的行尾更改为LF 在此处输入图片说明

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

相关问题 如何在Linux Docker容器上安装NPM - How can I install NPM on a Linux Docker container 两个 docker 容器(nginx 和一个 web 应用程序)不能一起工作(linux) - Two docker container (nginx and a web app) not working together (linux) Azure Docker Web 应用程序 - 无法更新容器设置的数据 - Azure Docker Web App - Failed to update data for container settings 如何从容器本身获取 Docker Linux 容器信息? - How can I get Docker Linux container information from within the container itself? 通过Azure Devops将Docker镜像部署到Linux上的Web应用程序失败 - Deploying docker image to web app on Linux via Azure Devops fails 如何从docker容器获取Linux系统上docker主机的IP? - How can I get the IP of the docker host on a Linux system from a docker container? 如何在Azure Linux Web应用程序上托管Angular - How to host an angular on Azure linux web app 在 Azure 上的 Linux 中启动时启动 Docker 容器 - Start a Docker container at startup in Linux on Azure 如何将bacpac文件还原到SQL Server Linux docker容器? - How can I restore a bacpac file to SQL Server linux docker container? 如何从 windows 主机访问我的设备到 docker linux 容器? - How can I access my device from a windows host to a docker linux container?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM