How to get SSH working w/Azure Web App For Containers (LINUX)

2022-05-27T18:26:22.11+00:00

Hello,
I have deployed a simple POC Spring boot application to Azure App Service. The application functions as expected. My Problem is that I cannot connect with SSH. I have followed the steps listed here:
https://learn.microsoft.com/en-us/azure/app-service/configure-linux-open-ssh-session
Here:
https://learn.microsoft.com/en-us/azure/app-service/configure-custom-container?pivots=container-linux#enable-ssh

As well as this forum post:
https://learn.microsoft.com/en-us/answers/questions/220501/azure-web-app-with-linux-container-ssh-login-issue.html
I log into the azure portal, find my app service from the Home screen, click on the SSH link to access the SSH blade and get a blank web ssh screen

What am I doing wrong???
Here is my Dockerfile:

FROM openjdk:13-jdk-alpine  
  
USER root  
  
# Add bash  
RUN apk update && apk add bash  
  
# add openrc for rc-service command  
RUN apk update && apk add openrc  
  
# openssh  
RUN apk update && apk add openssh \  
     && echo "root:Docker!" | chpasswd   
  
# Copy the sshd_config file to the /etc/ssh/ directory  
COPY sshd_config /etc/ssh/  
  
# Copy and configure the ssh_setup file  
RUN mkdir -p /tmp  
COPY ssh_setup.sh /tmp/  
  
RUN chmod +x /tmp/ssh_setup.sh && (sleep 1;/tmp/ssh_setup.sh 2>&1 > /dev/null)  
  
# Create dir where application will run  
RUN mkdir -p /opt/web-api-test1  
  
# Create config directory  
RUN mkdir -p /opt/web-api-test1/config  
  
RUN addgroup -S spring && adduser -S spring -G spring  
USER spring:spring  
  
# Copy over application.properties to config dir  
COPY --chown=spring src/main/resources/application.yaml /opt/web-api-test1/config/application.yaml  
  
# Make init.sh executable for spring:spring  
  
COPY --chown=spring init.sh /opt/startup/  
RUN chmod 755 /opt/startup/init.sh   
  
ARG JAR_FILE=target/*.jar  
COPY ${JAR_FILE} /opt/web-api-test1/web-api-test1-0.0.1-SNAPSHOT.jar  
  
EXPOSE 8080 2222  
  
ENTRYPOINT ["/opt/startup/init.sh"]  
  

ssh_setup.sh:

#!/bin/sh  
  
echo "running ssh-keygen..."  
ssh-keygen -A  
  
echo "ssh-keygen has executed..."  
  
#prepare run dir  
if [ ! -d "/var/run/sshd" ]; then  
    mkdir -p /var/run/sshd  
fi  
  
  

init.sh:

#!/bin/bash  
set -e  
  
echo "List contents of /etc/ssh..."  
searchDir=/etc/ssh  
for entry in "$searchDir"/*  
do  
  FILESIZE=$(stat -c%s "$entry")  
  echo "FILENAME: $entry FILE SIZE: $FILESIZE"  
done  
  
if [ $(ps ax | grep sshd | wc -l) -gt 0 ]; then  
  echo "sshd is running..."  
else  
  echo "sshd is not running..."  
fi  
  
echo "Check if port 8080 is open..."  
  
if [ $(netstat -an |grep 8080 | grep LISTEN | wc -l) -gt 0 ]; then  
  echo "Port 8080 is open..."  
else  
  echo "Port 8080 is closed..."  
fi  
  
echo "Check if port 2222 is open..."  
  
if [ $(netstat -an |grep 2222 | grep LISTEN | wc -l) -gt 0 ]; then  
  echo "Port 2222 is open..."  
else  
  echo "Port 2222 is closed..."  
fi  
  
echo Starting Spring Boot Rest API...  
exec java -jar /opt/web-api-test1/web-api-test1-0.0.1-SNAPSHOT.jar  
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
8,935 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Ryan Hill 30,281 Reputation points Microsoft Employee Moderator
    2022-06-15T18:05:52.267+00:00

    @Sullivan, Lawrence (US - Connecticut) , at first glance, your init.sh is missing the command /usr/sbin/sshd to start the SSH service. It's the last step on Enable SSH. I'm assuming your docker logs is showing sshd is not running... but let us know if it isn't.

    Also, mileage may very but I couldn't get ENTRYPOINT to run my startup script. I ended up having to use CMD ["<<path to startup script>>"]

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.