How to connect via ssh to specific container?

tyctor 0 Reputation points
2023-01-20T14:38:06.0533333+00:00

Hi

i have App Service with custom docker image scaled to two instances

i want to know how to connect via Web SSH console to each of that containers, when i trying to to that i am still connected to same container, how to choose which to connect?

thanks for reply

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
7,407 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Andrew Dello Stritto 80 Reputation points
    2023-01-21T04:02:50.2866667+00:00

    When you have an App Service with a custom Docker image scaled to multiple instances, you can use the Azure Portal to connect to the Web SSH console of each of the containers. Here's the process to follow:

    1. Go to the Azure Portal and navigate to the App Service resource for your custom Docker image.
    2. In the left navigation menu, click on "Containers".
    3. In the "Containers" page, you will see a list of all the instances (containers) running for your App Service. You can choose the one you want to connect by clicking on the "Connect" button next to the container.
    4. After clicking on "Connect" button, a new browser window will open with the Web SSH console for that container.

    Alternatively, you can use Azure CLI or Azure PowerShell to connect to the Web SSH console of a specific container.


  2. VenkateshDodda-MSFT 19,646 Reputation points Microsoft Employee
    2023-02-07T07:57:41.6433333+00:00

    @tyctor Thank you for reaching out to Microsoft Q&A, apologize for any inconvenience caused on this.

    Based on the shared information, we have understood that you application is hosted on app service using the custom containers, running on two instances (scaled to two instances) and you are seeking for some help on how to SSH into those instances.

    To connect via SSH to a specific container running on a custom Docker container, you must add SSH support to your Docker image by adding an 'sshd_config' file to your repository, which configures OpenSSH and must include the items that were explained here.

    Once the SSH is enabled, you can SSH to specific container that is running in your app service by pulling their instance names, SSH links using either Azure CLI cmdlets or through the Azure portal as well.

    Method 1: Azure CLI Method

    To pull the list of container instances running under your app service with their respective SSH links.

    az webapp list-instances --name <webappName> --resource-group <resourceGroupName> --query '[].{sshurl:consoleUrl,Name:name}' --output table

    Here is the sample output for reference:

    User's image

    select the ssh url of the specific container from the above and browse it in your browser to connect to that specific container or you can SSH to that container using the below CLI cmdlet.

    az webapp ssh --name <app-name> --resource-group <rg-name> --instance <instance-name>

    Method 2: Azure Portal

    To list all instances without Azure CLI, you can use Azure Resource Manager (ARM). Specifically, this resource:

    [...]/providers/Microsoft.Web/sites/<app-name>/instances?api-version=2018-02-01
    

    Azure Resource Explorer is quite helpful when navigating ARM:

    Instance names in ARM

    go to https://<app-name>.scm.azurewebsites.net/webssh/host/instance?=<instancename> directly to SSH to that specific container.

    Feel free to reach out to us if you have any further questions on this.

    0 comments No comments