Docker on Azure - SSH connection

Local hosting

Connecting to Docker Container on local machine is quite straightforward – just run linux-based image and use Docker Desktop embedded terminal.

No alt text provided for this image
No alt text provided for this image

Azure hosting

Running SSH connection on Azure App Service is a little bit more complicated.

There are required basically 3 steps:

 

  1. SSH server installation
  2. SSH server configuration
  3. Assure that SSH server is up and running

 

1. Package installation

Add install package SSH and Supervisor command in Dockerfile

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

Provided username and password root:Docker! are the default credentials for Azure App Service Web SSH console

2. SSH server and Supervisor configuration

Prepare SSH configuration in file named sshd_config

Port 			        2222
ListenAddress 		    0.0.0.0
LoginGraceTime 		    180
X11Forwarding 		    yes
Ciphers                 aes128-cbc,3des-cbc,aes256-cbc,aes128-ctr,aes192-ctr,aes256-ctr
MACs                    hmac-sha1,hmac-sha1-96
StrictModes 	       	yes
SyslogFacility 	        DAEMON
PasswordAuthentication 	yes
PermitEmptyPasswords 	no
PermitRootLogin 	    yes
Subsystem sftp internal-sftp

Prepare Supervisor configuration in file named supervisord.conf

[supervisord]
nodaemon=true

[program:ssh]
command=service ssh start

[program:api]
command=/usr/bin/dotnet /app/MyApp.dll --urls "http://*:80"]

Keep in mind that section [program:api] is entrypoint for contenerized .NET application.

3. Wrapping things up

Prepare startup script named startup.sh

#!/bin/s

echo "Starting supervisor process"
/usr/bin/supervisordh

Copy local config files in Dockerfile

RUN mkdir -p /var/log/supervisor 
COPY MyApp/Docker/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
COPY MyApp/Docker/sshd_config /etc/ssh/
COPY MyApp/Docker/startup.sh /app/

Expose port 2222 for SSH connection

EXPOSE 2222

Add Entrypoint in Dockerfile

CMD ["sh", "/app/startup.sh"]

Now when you will navigate to SSH section in Azure App Service you can launch Web SSH client and connect to the container

No alt text provided for this image
No alt text provided for this image