Tech Talks delivered by Wriju on Azure, Programming and DevOps
Demo steps and commands. This is just for idea. For tested script please use:
Nginx is a web app which can be used for demonstration purpose.
docker.io/library/nginx
Below are the steps for local docker
docker ps
If the above is not working and the error is
"Docker daemon is not running"
then
sudo service docker start
-d
will ensure that it runs in the background. Becasue without it the nginx will hold the prompt.
docker run -d docker.io/library/nginx
To confirm it is running use
docker ps
To enter inside the running container, (to use name either give a proper name or use the name auto generated by docker.
docker exec -it fc20b0420169 /bin/sh
Then in the tty run
curl http://localhost
If the page is showing then it is running inside the docker as a container.
Create the ACR via either portal or script. Portal is good for demo to clear the concept/
Then from local shell push it to Azure. Follow the below steps/
Create in Portal best for demo.
Azure CLI
acr=wgacr2
az acr create -g $g -n $acr --admin-enabled=true --sku=basic
First login to the ACR
docker login -u $acr -p SuperSecret $acr.azurecr.io
docker pull nginx
Then re-tag it based on the ACR. If the name of the ACR is
wgacr
then tag it as wgacr.azurecr.io/nginx:latest
To verify if the image is available locally and note the image_id
docker images
Then re-tag it as per the acr created above
image=$acr.azurecr.io/nginx:latest
docker tag IMAGE_ID $image
Push the image to ACR
docker push $image
Create a new ACI pointing to the ACR we have uploaded the nginx to through Portal. Again showing it in Portal is best for demo. But actually we must automate it.
From the overview of ACI get the public IP and open it in browser. You will see the landing page of Nginx.
You may also login to the Shell for ACR
az acr login -n $acr
Below will create ACI but prompt for the registry username and password.
az container create -g $g -n nginx420 --image=$image --ip-address=Public
To avoid that, you may pass two additional parameters
az container create -g $g -n nginx420 --image=$image --ip-address=Public --registry-username=$acr --registry-password=PASSWORD
To create a Azure App Service with container use portal.
# Create App Service Plan (Linux)
plan=asPlan420
az appservice plan create -g $g -n $plan --is-linux --sku B2
az webapp create -g $g -n wgwebapp420 -p $plan -i=$image -s wgacr -w PASSWORD
Create AKS cluster from Azure Portal. However, recommended is to use the Azure CLI.
alias k=kubectl
k get nodes
k create deploy nginx --image=$image
k expose deploy nginx --port=80 --type=LoadBalancer
k get svc
curl http:Public-Ip of the service