How to connect docker container through SSH after putting it in virtual networks

Jorge Guerra 1 Reputation point
2020-04-29T14:56:38.36+00:00

I was able to connect my custom container through ssh following the instructions https://learn.microsoft.com/en-us/azure/app-service/containers/configure-custom-container#enable-ssh but after I put the App Service in a virtual network it stopped working as the port 2222 changed

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

3 answers

Sort by: Most helpful
  1. Grmacjon-MSFT 16,191 Reputation points
    2020-04-30T05:42:38.503+00:00

    Hello @Jorge Guerra ,

    Are you getting any specific error messages? What did the port change to?

    Based on this VNet Integration document:

    "If you host your app on Linux with the built-in images, regional VNet Integration works without additional changes. If you use Web or Function App for Containers, you must modify your docker image to use VNet Integration. In your docker image, use the PORT environment variable as the main web server's listening port, instead of using a hardcoded port number. The PORT environment variable is automatically set by the platform at the container startup time. If you use SSH, the SSH daemon must be configured to listen on the port number specified by the SSH_PORT environment variable when you use regional VNet Integration. "

    0 comments No comments

  2. Andres Barcenas 1 Reputation point
    2020-05-01T19:49:40.213+00:00

    Hello @Grmacjon-MSFT ,

    Thanks for the detailed info. I am using a Web App service (Containers) in a Virtual Network and it is still not working. In my Dockerfile, I have the following:

    ENV PORT=80
    ENV PORT_SSH=2222
    EXPOSE $PORT $PORT_SSH

    Also, SSH is configured to listen on port 2222, the Web App Configurations settings have PORT and SSH_PORT defined and I am still able to SSH onto my container for debugging purposes.

    Any ideas?

    7903-screen-shot-2020-05-01-at-34750-pm.png


  3. Andres Barcenas 1 Reputation point
    2020-05-13T18:32:43.17+00:00

    I am good now. Thanks. I had to do the following inside my docker config:

    sed -i "s/SSH_PORT/$SSH_PORT/g" /etc/ssh/sshd_config