This tutorial deploys Drupal 7. However, the steps and pricipals can be applied to other customer containers too.
- Install the Azure CLI on your local machine.
- Install Docker CE on your local machine.
- Create a Docker Hub account or an [Azure Container Registry] (ACR).(https://docs.microsoft.com/en-us/azure/container-registry/container-registry-get-started-portal).
- Note your username and password for ACR or for Docker Hub. You'll need the credentials to push your Docker image to the repository. The ACR credentials are not the same as the credentials you use to log into the Azure portal.
- If you are new to Docker, read the overview.
- Install Visual Studio Code (VS Code).
- Install the VS Code Azure Account Extension .
- Install the VS Code Docker Extension.
WHY? The base image takes several minutes to create. Waiting several minutes everytime you deploy your web site gets tedious. Instead I like to create a base image, and then I build my main image everytime I deploy. Because the main image is based on the base image, the main image is created in less than 30 seconds.
- Run
docker build --rm -f "Dockerfile.BASE" -t creg7smg.azurecr.io/drupal-7-as-an-azure-app-service:base .
(NOTE: include the period. If you are using Docker Hub and not ACS, removecreg7smg.azurecr.io/
)
creg7smg.azurecr.io is the name of my Docker repository. Replace it with your repository name.
- Edit line 1 of
Dockerfile
. TheFROM
command should reference the base image name For example:FROM creg7smg.azurecr.io/drupal-7-as-an-azure-app-service:base
- Run
docker build --rm -f "Dockerfile.MAIN" -t creg7smg.azurecr.io/drupal-7-as-an-azure-app-service:latest .
- Run
docker run --rm -it -p 2222:2222 -p 80:80 drupal-7-as-an-azure-app-service:latest
- Open a web browser and navigate to http://localhost. You should see the Drual logo and the title "Select an installation profile"
- To get to the bash prompt inside of your now running container, in another terminal window, run:
docker exec -it vigilant_elion /bin/sh
Replace vigilant_elion with the name of your running container. To see what containers are running and their names, run
docker ps -a
If you successfully got to the webpage showing the Drupal logo, you can move to the next steps. Otherwise, it's time to troubleshoot.
- You'll now push (upload) both the base image and the main images to a container registery so that others, including Azure, can use it: Run
docker push creg7smg.azurecr.io/drupal-7-as-an-azure-app-service:base
. Again replace creg7smg.azurecr.io with the name of your Docker repository. - Now push the main image. Run
docker push creg7smg.azurecr.io/drupal-7-as-an-azure-app-service:latest
Prerequisite: complete the steps in the section above: How to Build the Base Image
-
Open a command prompt to use the Azure CLI. First, login. For help, see here.
az login
-
Edit the following parameters and then copy/paste into the Azure CLI. Remove the
$
in from each parameter if you are in bash. Keep the dollar signs if you are in PowerShell.
$SUBSCRIPTION="Your Subscription Name"
$RESOURCEGROUP="rg-smg-euwe"
$LOCATION="westeurope"
$PLANNAME="myappserviceplan"
$PLANSKU="B1"
$SITENAME="myappservice829601"
$RUNTIME="DOCKER|mycontainerregistryname.azurecr.io/drupal7_for_docker:base"
$IMAGENAME="mycontainerregistryname.azurecr.io/drupal7_for_docker:base"
$SERVERURL="https://mycontainerregistryname.azurecr.io"
$SERVERUSER="MyContainerRegistryUsername"
$SERVERPASSWORD="your password here"
Replace the values above with your custom values. For example, replace mycontainerregistryname with the name of your Azure container registery. Get your the
SERVERUSER
andSERVERPASSWORD
from the Azure Container Registery section of the Azure portal. TheRUNTIME
andIMAGENAME
should be identical except for theDOCKER|
To see a list all of the available subscriptions run
az account list -o table
Pricing for the different plan SKUs is here.
To get a list of Azure locations (regions) where a particular VM size (sku) is avaialble run:
az appservice list-locations --linux-workers-enabled --output table --subscription $SUBSCRIPTION --sku B1
List of potentially available regions for the LOCATION parameter: centralus, eastasia, southeastasia, eastus, eastus2, westus, westus2, northcentralus, southcentralus, westcentralus, northeurope, westeurope, japaneast, japanwest, brazilsouth, australiasoutheast, australiaeast, westindia, southindia, centralindia, canadacentral, canadaeast, uksouth, ukwest, koreacentral, koreasouth, francecentral
-
Set the default subscription for subsequent operations
az account set --subscription $SUBSCRIPTION
-
Create a resource group for your application
az group create --name $RESOURCEGROUP --location $LOCATION
-
Create an app service plan (a virtual machine) where your site will run
az appservice plan create --name $PLANNAME --location $LOCATION --is-linux --sku $PLANSKU --resource-group $RESOURCEGROUP
-
Create the web application (app service) on the plan. specify the node version your app requires
az webapp create --name $SITENAME --plan $PLANNAME --deployment-container-image-name $IMAGENAME --resource-group $RESOURCEGROUP
Pulling and running your image may need some time. Add or update the setting:WEBSITES_CONTAINER_START_TIME_LIMIT
= 600 -
Add two new app configurations:
az webapp config appsettings set -g MyResourceGroup -n MyUniqueApp --settings WEBSITES_ENABLE_APP_SERVICE_STORAGE=true
If the
WEBSITES_ENABLE_APP_SERVICE_STORAGE
setting is false, the /home/ directory will not be shared across scale instances, and files that are written there will not be persisted across restarts.
az webapp config appsettings set -g MyResourceGroup -n MyUniqueApp --settings WEBSITES_CONTAINER_START_TIME_LIMIT =600
Pulling and running your image may need some time. Add or update the setting: WEBSITES_CONTAINER_START_TIME_LIMIT
= 600
-
Configure the container information
az webapp config container set --docker-custom-image-name $IMAGENAME --docker-registry-server-url $SERVERURL --docker-registry-server-user $SERVERUSER --docker-registry-server-password $SERVERPASSWORD --name $SITENAME --resource-group $RESOURCEGROUP
-
FTP into your app service (aka web app) and update settings.php to reflect your Drupal database location. Instructions on how to FTP are here.
- Set up continuous delivery as described here.