Cloud-Native Mastery: Seamless Flask App Hosting on Azure Container Apps with Azure File Share Persistence

Have you ever wondered how to make your containerized app truly production-ready—ensuring your data survives redeployments, crashes, or scaling events? Today, we’ll walk through a real-world example: deploying a Flask warehouse app to Azure Container Apps with persistent storage, step-by-step using only the Azure Portal UI.

In this post, we’re going to show you how to deploy a real-world Python Flask application built to manage warehouse inventory. This app is intentionally simple and practical: no database, no ORM — it saves inventory data to a single item.json file inside the container at /usr/var/stores.

But here’s the catch: container file systems are ephemeral. Once the container is gone, your data is gone too… unless you use something like Azure Files.

We’ll leverage two powerful services from Azure:

🔹 Azure Container Apps — a fully managed platform for running microservices and containerized apps without worrying about Kubernetes.

🔹 Azure Files — a persistent, shareable file system that lets us store and retain data across container restarts or redeployments.

I. Build an Alpine Multi-Stage Docker Image:

– First, let’s get our hands on the app and shrink our container to the bare minimum with Alpine and Docker’s multi-stage builds.

– Open your terminal and clone the repository:

git clone https://github.com/vominhtri1991/warehouse_app.git
cd warehouse_app

– Create Dockerfile. It uses Alpine Linux for a super-small base image and a multi-stage build to keep only the essentials. If you want to see or tweak the Dockerfile, it might look something like this:

FROM python:3.12-alpine AS builder
WORKDIR /app
COPY requirements.txt .
RUN pip install --user -r requirements.txt

FROM python:3.12-alpine
WORKDIR /app
COPY --from=builder /root/.local /root/.local
ENV PATH=/root/.local/bin:$PATH
COPY . .
EXPOSE 8080
CMD ["python", "app.py"]

– Create .dockerignore file exclude .git when building image

– Build the image

docker build -t warehouse-app:1.0 .

– This results in a compact, fast container image—perfect for cloud deployment!

II. Create an Azure Container Registry and Push Your Image:

– Create an Azure Container Registry (ACR):

Go to Create a Resource > Containers > Container Registry.

– Push your image: In ACR, select Repositories to find your login server URL.

– Tag your image for Azure:

docker tag warehouse-app:1.0 <acr-login-server>/warehouse-app:1.0

– Log in to ACR from your terminal:

az acr login --name <acr-name>

– Push the image:

docker push <acr-login-server>/warehouse-app:1.0

III. Set Up Azure Storage Account and Azure File:

To make your data persistent, you need an Azure Storage Account with an Azure File Share.

  1. Create a Storage Account:
    • Create a Resource > Storage > Storage Account.
    • Enter your desired settings, then create.
  2. Set up an Azure File Share:
    • In the Storage Account, go to Data storage > File shares.

Click + File share, name it , and create.

IV. Deploy to Azure Container Apps with Azure Files as Persistent Volume:

1/Create a Container App:

  • Create a Resource > Containers > Container Apps.
  • Fill in the basics (name, environment, region, etc.).
  • For the container image, choose Azure Container Registry and select your pushed image.

– When you deploy to Azure Container Apps, ingress is how you expose your app to the outside world (public internet or internal networks). Think of ingress as the gateway that routes traffic into your container.

What is Ingress in Azure Container Apps?

  • Ingress allows you to control external access (HTTP/HTTPS) to your app.
  • You can expose your app on standard web ports (like 80 or 443).
  • You decide if your app is public (internet-accessible) or only accessible inside your Azure environment.
  • Azure’s ingress system will route requests on port 80/443 to your app’s internal port (e.g., 8080).

Target Port: Set 8080 (the port exposed by your Docker container)

2/Register File Share in Managed Environment:

Go to Azure Portal → Container Apps Environments > Select your managed environment (where your container app will run).

– Settings > Azure Files

– Click Add > Server Message Block

3/Add a Volume using Azure Files:

– In the Container App’s “Volumes” section, click Add Volume.

–  Choose Azure Files, then select your Storage Account and File Share.

–  Mount it as a volume, for example:

  • Volume name: items-vol01

– Assign a Mount Path To Container: Select your Container App>  On the left, under Settings, choose Containers.

– Choose tab Volume mounts > Add

4/Accessing Your App: Get the Ingress Endpoint:

Once your Azure Container App is deployed and ingress is enabled, Azure provides you with a public endpoint (URL) so you can access your app from anywhere.

How to Find Your App’s Public URL

  1. Go to your Container App in the Azure Portal.
  2. In the left menu, click on “Ingress”
  3. Under the Ingress section, you’ll see the Endpoint field.

– Copy this URL—you’ll use it to access your app in a browser

– Using form to add new items

V. Swap Out Your Container – Data Still Safe!

Now let’s put our persistent storage to the test! We’ll update your Azure Container App by deploying a new container image (or a new version), and delete the old container. Because we’re using Azure Files as a mounted volume, your data—such as all the items you added—will stay safe and sound.

Step 1: Create a New Container in Your Existing Container App

  1. Go to your Container App in the Azure Portal.
  2. In the left menu, click “Containers.”
  3. Click “Add container.”
  4. For the new container, you can:
    • Use a new image (for example, a new tag/version you’ve pushed to ACR)
    • Or use the same image as before (just for demo)
  5. Attach the existing volume (Azure File Share) to the new container at the same mount path (/usr/var/stores).
  6. Review environment variables and settings as needed.

– Once the app redeploys, go back to your Ingress Endpoint (the public URL you copied earlier).

– Access your app and check the items list > You’ll see that all your previously created items are still present.

VI. Conclusion: What We Built & What We Learned

In this hands-on journey, we took a simple Flask warehouse app from source code to a resilient, production-ready deployment on Azure. Here’s a quick recap of what we accomplished:

  • Cloned and containerized the app using an optimized Alpine-based multi-stage Docker build for minimal image size and fast deployments.
  • Pushed the image to Azure Container Registry, making it available for cloud-native deployments.
  • Created an Azure Storage Account and Azure File Share, setting up a persistent storage solution designed for real-world reliability.
  • Deployed the app on Azure Container Apps, mounting the file share as a volume so your data lives outside the container lifecycle.
  • Enabled ingress to give the app a public endpoint, tested by adding and retrieving demo items.
  • Swapped out containers within the same app environment, proving that data remains safe and accessible thanks to persistent storage.

Thanks for following along! If you have questions or want to see more real-world Azure tutorials, let me know in the comments or reach out directly. 🚀

Leave a Comment

Your email address will not be published. Required fields are marked *