This blog shows three (3) different ways to host an app on Azure safely and efficiently. The three ways are as follows:
- Azure Container Instances.
- Web App for Containers + Azure Database for PostgreSQL.
- Virtual Machine + Docker Compose.
REQUIREMENTS:
• Microsoft Azure Account.
• Dockerhub Account.
• Dockerhub desktop App installed on your local computer.
No.1: Azure Container Instances.
First thing to do is to write your docker-compose.yaml and make sure that script is in order then follow these steps:
(a). Build the Docker Image Locally on your PC.


This makes Docker to download the base images, builds your image, then reports that the network, the volume and two containers were created or started.

docker compose ps & docker compose logs app : Docker Compose ps helps you to list the running containers while Docker compose Logs are the first place to look whenever something behaves strangely. Then open http://localhost:3000 in your browser.


This is proof that the full chain works and that the browser talks to the app and the app talks to the database.
Publish Your Image to Docker Hub: At this moment, your app image exists only on your computer. Azure can't access your laptop, so you need to upload the image to a registry Azure can pull from.
Now log into your Azure Account in your terminal using Azure CLI command and create a resource group.

I created some variable to be use continuesly.

Also I create an aci-notes.yaml file that tells Azure which containers to run and how to configure them. Azure reads this file the way Docker Compose reads docker-compose.yaml.

and do this to fetch IP address:

Checking to see if the container is okay.
open in browser:
No. 2: Web App for Containers and a Managed Database: Azure handles backups, patching, high availability and scaling for you. The app itself runs on Azure Web App for Containers, a platform built for hosting containerized web apps, with automatic HTTPS, scaling and deployment slots. This is the recommended pattern.
Create the managed PostgreSQL server.

Checking the server to capture its address.

Creating the App Service plan.

Creating the web app from your image.

Point the app at the managed database.

No.3: Virtual Machine + Docker Compose: Sometimes you want full control over the server, custom software, specific networking, or simply to understand what platforms like Web App for Containers do behind the scenes. In this option you rent a Linux server, install Docker on it yourself, and run the same kind of compose file you used locally. You are now the system administrator.
Create a resource group and a small Ubuntu Linux server inside it.


Install Docker and Docker Compose on the VM.
- Install helper tools.
Let user run Docker without sudo and apply the group change.


Test the App from your own computer.


Note: if you are running a demo, then don’t forget to always clean-up after your practices in order not to incur charges on Azure. To achieve this always delete the resource group by running the command below on your terminal.
az group delete --name notes-vm-rg --yes --no-wait
Replace the name with your own resource group name.
Thank you for reading this.

























Top comments (0)