Sample docker image is at https://hub.docker.com/r/michimune/helloaspnetcore/
This is an example web application to learn the following three scenarios how to use App Service on Linux:
- Build a custom Docker image and deploy it to your web app with Azure CLI
- Enable CI/CD for the web app
- Use SSH session from Advanced Tools (aka Kudu)
- Install Docker
- Install VS Code
- Install Azure Extension Pack and Docker extension to VS Code (https://marketplace.visualstudio.com/items?itemName=ms-vscode.vscode-azureextensionpack)
- Make sure multi-factor authentication (MFA) works on your local machine
- Clone the repository to your local machine.
- Open the project with VS Code.
- Build the project by typing Ctrl+Shift+P docker:build, choose Dockerfile.
- Publish the docker image by typing Ctrl+Shif+P docker:publish, and a tag (e.g. michimune/helloaspnetcore:latest).
- Launch Docker Azure CLI extension by typing Ctrl+Shift+P Docker:Azure CLI. This will launch a docker container with Azure CLI configured.
- Type
az login
. You will be prompted to navigate to http://aka.ms/devicelogin. Browse the page and copy and paste the code shown (~10 length characters) to the login page to complete the sign-in. When successful, you will see the list of subscriptions in your terminal. - Create a web app:
az webapp create --plan {AppServicePlanName} -g {ResourceGroupName} --name {SiteName}
- Set the docker container name to the web app:
az webapp config set -g {ResourceGroupName} --linux-fx-version "DOCKER|michimune/helloaspnetcore:latest" --name {SiteName}
- Browse the site by launching http://{SiteName}.azurewebsites.net/.
- In Azure CLI window, enable CI/CD:
az webapp config appsettings set -g {ResourceGroupName} --settings DOCKER_ENABLE_CI=true --name {SiteName}
- Set deployment username and password (If needed):
az webapp deployment user set --user-name {Username}
- Browse http://dockerhub.com and navigate to the repository.
- Choose Settings, add webhook:
- Name: anything (e.g. docker)
- Link:
https://{Username}:{Password}@{SiteName}.scm.azurewebsites.net/docker/hook
- Update message.txt (For example, append one character) and save it.
- Type Ctrl+Shift+P docker:build, choose Dockerfile. Type or choose the same tag.
- Type Ctrl+Shift+P docker:publish, choose the same tag.
- Wait for a while and refresh the page to confirm that the text is updated.
- Log in to the Azure portal at https://portal.azure.com/. Navigate to App Services and choose the web app that was created during the above scenario.
- Choose Advanced Tools, and click Go. A new Kudu session is opened.
- Choose Debug console followed by SSH.
- Type
apt-get install vim -y
to install vim. - Type
vi message.txt
, edit the contents (e.g. append!
by typingA!<ESC>
) and typeZZ
to save and exit. - Refresh the page.