gpt4 book ai didi

linux - 如何通过 ssh 连接到 Azure 上的 "Web App On Linux"docker 容器?

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:55:57 25 4
gpt4 key购买 nike

如何使用新的“Linux 上的 Web 应用程序”服务 ssh 进入容器?

目前处于预览模式,我不确定这是否可行,或者我已经监督了设置。

最佳答案

这是我在 Linux 容器中将 ssh 与 asp.net core 应用程序一起使用的示例:

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"]

.net core项目根文件夹中的init.sh

service ssh start
dotnet MyApp.dll

sshd_config位于.net core项目的根文件夹

#
# /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

enter image description here

关于linux - 如何通过 ssh 连接到 Azure 上的 "Web App On Linux"docker 容器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42704656/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com