Cloudnavium

Logo

Cloudnavium is a personal tech blog where I document my journey learning DevOps, Azure, cloud architecture, AI, and whatever else grabs my curiosity. I do not have all the answers. This is a space to explore, make mistakes, and grow. It is not a place to show off expertise. It is a place to learn. If you are learning too, you are in good company.

Deploying a Local Docker Container to Azure Container Registry (ACR)

AI usage

2025-04-13

Local Docker Container to ACR.png

I was doing some practice on creating containers utilizing Docker, and I was actually quite relieved because it was a lot less intimidating than I believed. I was able to create a simple Docker container and push it to Azure Container Registry. Below is a step-by-step guide on how I did it.


1. Setting Up the Directory

  1. Create a directory to hold all your program files and dependencies. I named mine localcontainer.

  2. I used ChatGPT to generate a simple Flask web app to test the container's functionality. Normally, this code would go in app.py (or whatever your entry file is depending on your language).

  3. Add all required modules to a requirements.txt file.

  4. Create a Dockerfile — this file tells the container what to install, configure, and run.


2. Building the Docker Image Locally

  1. Build the Docker image:

    docker build -t flask-test .
    
  2. Verify the image exists:

    docker images
    
  3. Run the container locally to test:

    docker run -p 5000:5000 flask-test
    

3. Create Azure Container Registry (Using Azure CLI)

  1. Log in to Azure:

    az login --tenant <tenant-id>
    
  2. Create the ACR:

    az acr create --name <acr-name> --resource-group <resource-group-name> --sku Basic
    
  3. Enable admin access to allow Docker push/pull:

    az acr update --name <acr-name> --admin-enabled true
    

When it comes to enabling admin access, it's okay to do it in a lab environment but service principals are safer.


4. Push Image to ACR

  1. Login to ACR:

    az acr login --name <acr-name>
    
  2. Tag the Docker image:

    docker tag flask-test <loginserver>/<repository>:v1
    
  3. Push the image to ACR:

    docker push <loginserver>/<repository>:v1
    
  4. Verify it was pushed:

    az acr repository list --name <acr-name> --output table
    az acr repository show-tags --name <acr-name> --repository <repository> --output table
    

Notes

  • Make sure Flask is listening on 0.0.0.0:5000.

  • If deploying to Azure Container Instance (ACI), ensure port 5000 TCP is enabled.


Quick Command Recap

docker build -t flask-test .
docker images
docker run -p 5000:5000 flask-test

az login --tenant <tenant-id>
az acr create --name <acr-name> --resource-group <resource-group-name> --sku Basic
az acr update --name <acr-name> --admin-enabled true

az acr login --name <acr-name>
docker tag flask-test <loginserver>/<repository>:v1
docker push <loginserver>/<repository>:v1

az acr repository list --name <acr-name> --output table
az acr repository show-tags --name <acr-name> --repository <repository> --output table

I used ChatGPT to organize this post, but all the technical steps, command-line work, troubleshooting, and visual documentation were performed and validated by me.