AZURE WEB APP WITH LINUX CONTAINER SSH LOGIN ISSUE

Mohit Kumar Sharma 86 Reputation points
2021-01-06T07:32:44.403+00:00

Hi,

I am using azure web app with container and I also expose the port 2222 in docker-file but I am not able to ssh login in the server.
Dockerfile:
EXPOSE 80 2222

I am getting this error.
SSH CONNECTION CLOSE - Error: connect ECONNREFUSED 172.16.1.3:2222 CREDENTIALS

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
6,875 questions
0 comments No comments
{count} vote

2 answers

Sort by: Most helpful
  1. SnehaAgrawal-MSFT 18,361 Reputation points
    2021-01-06T11:30:35.17+00:00

    Thanks for asking question!
    Could you please confirm how are you trying to open SSH session, To open SSH session in browser paste the following URL into your browser and replace <app-name> with your app name: https://<app-name>.scm.azurewebsites.net/webssh/host

    Also, You're required to authenticate with your Azure subscription to connect. Once authenticated, you see an in-browser shell, where you can run commands inside your container.

    Refer to this document: Open an SSH session to a Linux container in Azure App Service

    Also, To add further the most common cause of an inability to SSH into a custom container is either the Web App isn't running or the Kudu container isn't running. Therefore, if you are unable to SSH into your app container, you should check.

    1. Ensure that the Web App is currently running.
    2. Ensure that the Kudu site is currently running.

    Please let us know.

    1 person found this answer helpful.

  2. SnehaAgrawal-MSFT 18,361 Reputation points
    2021-01-07T04:50:50.527+00:00

    Sure, Thanks for reply! You should have full privilege rights with your Azure subscription to connect.

    Also, could you please double check on enabling SSH in a custom container, the following requirements should be met.

    1. The Docker image must be built so that openssh-server is installed. To ensure that openssh-server is installed, the following must be included in the Dockerfile used to build the image.

    RUN apt-get update \
    && apt-get install -y --no-install-recommends openssh-server \
    && echo "root:Docker!" | chpasswd

    1. The Docker image must include a proper sshd_config file in the /etc/ssh directory. You can copy the contents of the sshd_config file located here . You also need to ensure that the sshd_config file is part of the build
      context when the Docker image is built, and you need to copy the file to the correct directory in the image using the following in the
      Dockerfile.

    COPY sshd_config /etc/ssh/

    1. Port 2222 must be exposed via the Dockerfile. To expose port 2222, the following line must be included in the Dockerfile. EXPOSE 2222 Note that you should also expose the port that will be used when browsing the app. This will typically be port 80, so the EXPOSE
      instruction may look like this.

    EXPOSE 2222 80

    1. The SSH service must be started when the container is started. You need to create a startup script for the container. Inside of that script, you should start the SSH service. Here is an example of script
      code that will do this. #!/bin/bash
      service ssh start Note that #!/bin/bash is required as the first line of this script. Otherwise, it will not work. The script can be named anything. In our documentation, we use init_container.sh as a recommendation.
    2. The startup script must be included in the image, and the script should be called via the Dockerfile. The startup script must be included in the build context when the Docker image is built. The following lines also need to be part of
      the Dockerfile in order for the script to execute.

    COPY init_container.sh /opt/startup
    RUN chmod 755 /opt/startup/init_container.sh
    ENTRYPOINT ["/opt/startup/init_container.sh"]

    Reference: https://learn.microsoft.com/en-us/azure/app-service/configure-custom-container?pivots=container-linux#enable-ssh

    Hope this helps. Let us know Incase issue persists.

    1 person found this answer helpful.