user1497277
user1497277

Reputation: 469

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?

It is currently in preview mode, I'm not sure that it is not possible yet or I have overseen the settings.

Upvotes: 3

Views: 9517

Answers (6)

Sgedda
Sgedda

Reputation: 1531

Here is an example that I got working with ssh together with a asp.net core app in linux container:

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

service ssh start
dotnet MyApp.dll

sshd_config in root folder of .net core project

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

Upvotes: 8

pansekta
pansekta

Reputation: 31

For anyone having issues with @sgedda's answer as @Manish Jain is having, try using:

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

It worked for me.

Upvotes: 3

AGDevX
AGDevX

Reputation: 71

I found @Sgedda's reply to be very helpful. I followed his example to the letter, but I kept getting this 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. 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.
  2. Changed the encoding of the init.sh and sshd_config files to ISO 8859-15 using VS Codeenter image description here
  3. Changed the line endings of the init.sh and sshd_config files to LF using VS Code enter image description here

Upvotes: 2

sebagomez
sebagomez

Reputation: 9599

As of today (4/1/2019) it is possible according to this doc: Connect to Web App for Containers using. It's kind of hacking but it does the trick.

Not an April fool's joke.

Upvotes: 2

Shui shengbao
Shui shengbao

Reputation: 19195

For now, It is not possible. Please refer to this feedback.

Update on 2017-6-8

Now, it is possible, please refer to SSH support for Azure Web App on Linux.

Upvotes: 3

gwcodes
gwcodes

Reputation: 5690

I don't believe you can. But depending on what you want to do (e.g. view log files), you could use bash from Kudu (via Advanced Tools > Debug console > Bash)

That said, Web App On Linux is in preview - so SSH may be possible in the future!

Upvotes: 1

Related Questions