Description: How to deploy node.js express dockerized app on Azure
docker image build -t <dockerhub username>/<image-name> .
example: docker image build -t yongye0997/docker_python .
docker container run --name <container name> -p <local port:container port> <image name>
example: docker container run --name fastapi_testing -p 8000:8000 yongye0997/docker_python
docker push <docker username>/<image name>
docker push yongye0997/docker_python
Azure for Students
subscriptionaz login
, this will redirect to login pageStep 1: Create a Resource Group
az group create --name <name of resource group> --location <name of location>
example: az group create --name api-resource-group --location eastus
Step 3: Verify that you created a resource group successfully by typing az group list
or az group list --output table
Step 4: Create a Container Registry (ACR)
az acr create --resource-group <name of resource group> --name <name of container registry> --sku Basic --admin-enabled true
example: az acr create --resource-group api-resource-group --name yongyeapiacr --sku Basic --admin-enabled true
Basic
plans and enable admin accessStep5: Push Docker Image to DockerHub or ACR
az acr login --name yongyeapiacr
--platform=linux/amd64
docker build -t <image name>:<tag> .
example: docker build -t express-demo:latest .
M1 chip example: docker image build --platform=linux/amd64 -t express-demo:latest .
docker tag <image name in step 2> <name of ACR>.azurecr.io/<image name in step 2>
example: docker tag express-demo:latest yongyeapiacr.azurecr.io/express-demo:latest
docker push yongye0997/express-demo
docker push yongyeapiacr.azurecr.io/express-demo
express-demo
Step6: Create a Container App Environment
az containerapp env create --name <name of container app environment> --resource-group <name of resource gorup we created in step 1> --location eastus
example: az containerapp env create --name expressDemoAppEnv --resource-group api-resource-group --location eastus
Step7: Create a container App (Be very careful with this step since it involves with lots of flags)
ingress
to receive trafficaccepting traffic from anywhere
for Ingress trafficaz containerapp create
--name <name of container app>
--resource-group <name of resource group>
--environment <name of container environment>
--image <name of image from the ACR or docker hub>
--target-port <port number>
--ingress external
Pulling image from Docker Hub example:
az containerapp create
--name yongye-express-api-demo-app
--resource-group api-resource-group
--environment expressDemoAppEnv
--image yongye0997s/express-demo:latest
--target-port 8080
--ingress external
Pulling image from ACR example:
# need to manually specify registry-server, registry-username, or registry-password if authentication is required, link: https://github.com/microsoft/azure-container-apps/issues/863#issuecomment-1669564470
az containerapp create
--name yongye-express-api-demo-app
--resource-group api-resource-group
--environment expressDemoAppEnv
--image yongyeapiacr.azurecr.io/express-demo:latest
--registry-server yongyeapiacr.azurecr.io
--registry-username yongyeapiacr
--registry-password <your password>
--target-port 8080
--ingress external
Step8: You should receive an application url on Terminal or Azure container app website. My application link is: https://yongye-express-api-demo-app.yellowdune-bb83b275.eastus.azurecontainerapps.io/hello
Step 9: Thank you!
# build the image
docker image build -t <image name> .
# use the image to run container
docker container run --name <container name> -p <local port: container port> -d <image name>