Nginx in App Service [Web App For Containers]

Running Nginx server in Web App For Container

Web app for containers (WafC), makes it really easy to run any docker image. This post explains how to run a static site hosted on nginx.

az webapp create -g "JlawDemoRG" -p "JlawDemoASP" -n "JlawnginxSample"
  --multicontainer-config-type COMPOSE 
  --multicontainer-config-file <composefile.yml>

A sample compose configuration to run nginx

Paste the below content in a file, and use that file in the az-webapp command as the –multicontainer-config-file argument.

version: '3.1'

services:

  nginx:
    image: nginx:1.7.9
    ports:
      - 8080:80
    volumes:
      - ${WEBAPP_STORAGE_HOME}/site/wwwroot:/usr/share/nginx/html

Other configuration on the web app.

Since this app requires azure app service storage, we use an app setting to enable that functionality.

WEBSITES_ENABLE_APP_SERVICE_STORAGE, set to "true"

What is the app setting WEBSITES_ENABLE_APP_SERVICE_STORAGE?

Azure App Service provides a persistent storage exposed over SMB available to all apps on the service. That said, not all docker web apps require a persistent storage for app contents since the docker image itself typically contains the app/content built in. In this particular example, the nginx image used is an official image it is a web server with no contents hosted.

Configuring WEBSITES_ENABLE_APP_SERVICE_STORAGE allows the docker container to use the app service storage.

What is the magic ${WEBAPP_STORAGE_HOME}?

This is an alias used to reference the app service storage. App Service Storage has precreated LogFiles and site folders, with a wwwroot folder under the site. ${WEBAPP_STORAGE_HOME}/site/wwwroot:/usr/share/nginx/html specifies that the site/wwwroot folder should be mounted to /usr/share/nginx/html. This overrides the nginx’s default content directory with the app service storage. With this configuration, it is now possible to either use git or FTP to publish contents to this web app.