The purpose of this Hands on Lab (HOL) is to have an understanding of how to:
- Install Docker Host and Docker CLI tools
- Build a custom Docker Image
- Push your custom Docker Image to a Docker Registry (this can be public/private Docker Hub or a private Azure Container Registry aka "ACR")
- Create an Azure App Service (Specifically a "Web App for Containers" Service)
- Deploy an instance of your custom Docker Image (container) to Azure App Service
- Create a webhook to update your Azure App Service when your custom Docker Image has been updated (new updates pushed to the Container Registry)
- Azure Subscription or Sign up for Azure Fre Trial
- You will require access to a Mac Environment with Docker for this Hands on Lab (HOL)
Requires Apple Mac OS Yosemite 10.10.3 or above. Download Docker Toolbox for previous OS versions.
Documentation : Docker on Mac
Check out the video on how to install docker on Windows:https://www.youtube.com/watchv=lNkVxDSRo7M
For manual isntructions see below ....
Double-click Docker.dmg to start the install process.
When the installation completes and Docker starts, the whale in the top status bar shows that Docker is running, and accessible from a terminal..
Open a command-line terminal, and try out some Docker commands.
Run docker version
to check that you have the latest release installed.
Run docker run hello-world
to verify that Docker is pulling images and running as expected.
Install GIT if not already installed on your machine
# Create a folder and go to that folder
mkdir docker
cd docker
# Now Clone the repo locally
git clone https://github.com/Azure-Samples/docker-django-webapp-linux.git
cd docker-django-webapp-linux
**Always run docker CLI commands on elevated privileges *
# You can edit the app by making changes to the html files under /app/templates/app folder. use vim [filepath] to open the file to edit. Here are commands if you are not familiar with vim
# Now build the image [Usage : docker build -t [Image Name]:[tag] Dockerfile Path]. Since you are inside docker-django-webapp-linux folder you can use . to select the docker file in the current working directory
docker build -t starterapp:latest .
# Run docker images to see your image listed. Make a note of the IMAGE ID for your built image
docker images
# Sample output:
REPOSITORY TAG IMAGE ID CREATED SIZE
starterapp latest <your_image_id> 18 minutes ago 735MB
Login via portal and launch cloud shell https://docs.microsoft.com/en-us/azure/cloud-shell/quickstart
1. Launch Azure Cloud Shell from the top navigation of the Azure portal
If it's the first time you open the Cloud Shell:
2. Select a subscription to create a storage account and Azure file share
3. Select "Create storage"
Tip
- You are automatically authenticated for Azure CLI 2.0 in every session.
- If you have multiple subscriptions, please use the following to choose the default subscription as the Azure Pass provided to you
az account set --subscription my-subscription-name
Note: You can also locally install Azure CLI on your local development environment as per these instructions
# Use the Azure Cloud Shell console for the next commands.
# Use the[az appservice list-locations](https://docs.microsoft.com/en-us/cli/azure/appserviceview=azure-cli-latest#list-locations) Azure CLI command to list available locations.
# Create a resource group for the ACR and web app
az group create --name myResourceGroup --location "West US"
# Create a ACR container registry. Choose a unique name instead of myContainerRegistry
az acr create --resource-group myResourceGroup --name myContainerRegistry --sku Basic
# Enable admin credentials on the new registry
az acr update -n myContainerRegistry --admin-enabled true
# Get Login credentials
az acr credential show --name myContainerRegistry
# Use your previously used local command line (PowerShell or CMD) for the next commands.
# Login to ACR to pull or push images. Use the credentials received from the previous command. Ignore the security warning. Run docker CLI commands on administrator mode in Powershell on Command Prompt
docker login myContainerRegistry.azurecr.io -u <YOUR-USERNAME> -p <YOUR-PASSOWRD>
# Tag the locally built image to ACR repo. Replace ```your_image_id``` with Image ID from locally building your image above.
docker tag <your_image_id> myContainerRegistry.azurecr.io/starterapp:latest
# Push docker image to ACR . Replace ```<acrLoginServer>``` with the login server name of your ACR instance.
docker push myContainerRegistry.azurecr.io/starterapp:latest
# Verify the Push was successful. Do it in the Azure Cloud Shell
az acr repository list -n myContainerRegistry
#Executenext commands in the Azure Cloud Shell
az appservice plan create --name myAppServicePlan --resource-group myResourceGroup --sku S1 --is-linux
az webapp create --name <app_name> --resource-group myResourceGroup --plan myAppServicePlan --deployment-container-image-name <your-docker-user-name>/starterapp:latest
az webapp config container set
command to assign the custom Docker image to the web app. Replace <app_name>, , , and . For Azure Container Registry, is in the format https://.azurecr.io.
az webapp config container set --name <app_name> --resource-group myResourceGroup --docker-custom-image-name myContainerRegistry.azurecr.io/starterapp --docker-registry-server-url https://myContainerRegistry.azurecr.io --docker-registry-server-user <registry-username> --docker-registry-server-password <password>
# Run this command
az webapp restart --resource-group myResourceGroup --name <your_app_name>
https://<your_app_name>.azurewebsites.net
Go back to Azure Virtual machine to make more changes. Build the image and then push it to your Docker Hub repository. Follow the steps above to do the same
http://<your_app_name>.azurewebsites.net
# You can obtain the Webhook URL
az webapp deployment container show-cd-url -n <your_app_name> -g myResourceGroup
# For the Webhook URL, you need to have the following endpoint:
https://<publishingusername>:<publishingpwd>@<your_app_name>.scm.azurewebsites.net/docker/hook
# You can obtain your publishingusername and publishingpwd by downloading the web app publish profile using the Azure portal.
Replace <webhook-url-web app>
with web hook URL endpoint https://<publishingusername>:<publishingpwd>@<your_app_name>.scm.azurewebsites.net/docker/hook
az acr webhook create --registry myContainerRegistry --name myacrwebhook01 --actions push --uri <webhook-url-web app>
When the image gets updated, the web app get updated automatically with the new image.
Go back to Azure Virtual machine to make more changes. Build the image and then push it to your Docker Hub repository. Follow the steps above to do the same
http://<your_app_name>.azurewebsites.net