Azure Docker Container — DevOps

Always learning
6 min readMar 16, 2024

A virtual machine (VM) is a software implementation of a physical computer that can run its own operating system (OS) and applications.

A container is a lightweight, standalone, executable package that includes everything needed to run a piece of software, including the code, runtime, system tools, and libraries.

VM includes a full copy of an operating system, while a container shares the host system’s kernel. This means that VMs are more isolated from one another and from the host system, but also require more resources. Containers, on the other hand, are more lightweight and portable, but offer less isolation.

Non-containerized applications

  • Deploy new software that runs on the host machine (not in docker or anything).
  • Upgrade/update said software when needed i.e from a git repository.
  • Monitor the logs of each node running said software.

The Docker platform is an open-source containerization technology that allows developers to package and distribute applications as containers.

Docker makes use of a client-server architecture. The Docker client talks with the docker daemon which helps in building, running, and distributing the docker containers. The Docker client runs with the daemon on the same system or we can connect the Docker client with the Docker daemon remotely.

Docker daemon manages all the services by communicating with other daemons. It manages docker objects such as images, containers, networks, and volumes with the help of the API requests of Docker.

The Docker client is the primary interface that users interact with when using Docker. It’s a command-line tool that communicates with the Docker daemon to execute Docker commands. The Docker client can run on the same system as the Docker daemon, or it can connect to a remote Docker daemon.

buymeacoffee ☕ 👈 Click the link

Containers provide a lightweight, isolated environment that includes all the necessary dependencies to run an application, such as libraries, frameworks, and system tools.

Docker registries are essentially libraries of images and act as repositories where Docker images are stored. They allow users to distribute and share Docker images across different environments.

Docker maintains a public registry known as “Docker Hub”, but there are also several other registries provided by various vendors such as Azure Container Registry, Amazon Elastic Container Registry, and Google Container Registry.

Docker operates on several key objects that are essential to its functioning. These include Images, Containers, Networks, Volumes, and Plugins.

  • Docker Images
  • Docker Containers
  • Docker Volumes
  • Docker Networks
  • Docker Plugins

Docker Swarm is a container orchestration tool. That is, it allows for the creation of a cluster of docker hosts and turns them into a single virtual server.

This enables your application running on containers to achieve high performance and high availability by distributing it between available hosts within the cluster.

HandsOn 🚀 https://ibrahims.hashnode.dev/docker-swarm-handson 💡

Azure Docker provides the best, accurate, easy, and faster solution to migrate your applications to the Azure cloud, allows vast security, and helps contemporize the app services.

Using Docker deployment on Azure, developers can easily deploy modern and standard Linux (or) Windows-based applications with enterprise-level security, support, and scale.

Azure Container Instances (ACI) is a serverless service provided by Microsoft Azure that allows you to run Docker containers.

Create a New Project

Goto repo → Import a repository

Git URL https://github.com/Ibrahimsi/todoapp-docker.git

Dockerfile is a text document containing all the commands the user requires to call on the command line to assemble an image. A Dockerfile is the Docker image’s source code. Create a Dockerfile.

Multi-stage builds, you use multiple FROM statements in your Dockerfile. Each FROMinstruction can use a different base, and each of them begins a new stage of the build. You can selectively copy artifacts from one stage to another, leaving behind everything you don't want in the final image.

Dockerfile code

FROM node:18-alpine AS installer
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build
FROM nginx:latest AS deployer
COPY --from=installer /app/build /usr/share/nginx/html

Azure Container Instances (ACI) is a service that enables a developer to deploy containers on the Microsoft Azure public cloud without having to provision or manage any underlying infrastructure. The service supports both Linux containers and Windows containers.

Azure Container Registry is a private registry service for building, storing, and managing container images and related artifacts. In this quickstart, you create an Azure container registry instance with the Azure portal.

Create a Azure Container Registry

Validation passed

Access keys give you full rights to everything in your storage account.

Put a tick you get a admin user credentials

Lets go to the pipeline → Create a new pipeline

Pipeline → Create → Azure Repos Git → Docker (Build and push an image to Azure Container Registry)

Verify the subscriptions

Three task

  1. Azure CLI authenticator
  2. Build an docker images
  3. Container Create

Log in to an Azure Container Registry through the Docker CLI

Create a container group

Task added

Save and run the pipeline. Successfully build the job

Check ACR

Container created

Pipeline full code

# Docker
# Build and push an image to Azure Container Registry
# https://docs.microsoft.com/azure/devops/pipelines/languages/docker

trigger:
- main

resources:
- repo: self

variables:
# Container registry service connection established during pipeline creation
dockerRegistryServiceConnection: 'ce86373d-4d75-4b34-b778-d5b8eb8dd4b0'
imageRepository: 'todoapp'
containerRegistry: 'ibrahims.azurecr.io'
dockerfilePath: '$(Build.SourcesDirectory)/Dockerfile'
tag: '$(Build.BuildId)'

# Agent VM image name
vmImageName: 'ubuntu-latest'

stages:
- stage: Build
displayName: Build and push stage
jobs:
- job: Build
displayName: Build
pool:
vmImage: $(vmImageName)
steps:
- task: AzureCLI@2
inputs:
azureSubscription: 'Pay-As-You-Go(f30deb63-a417-4fa4-afc1-813a7d3920bb)'
scriptType: 'bash'
scriptLocation: 'inlineScript'
inlineScript: 'az acr login --name=$(containerRegistry)'

- task: Docker@2
displayName: Build and push an image to container registry
inputs:
command: buildAndPush
repository: $(imageRepository)
dockerfile: $(dockerfilePath)
containerRegistry: $(dockerRegistryServiceConnection)
tags: |
$(tag)
- task: AzureCLI@2
inputs:
azureSubscription: 'Pay-As-You-Go(f30deb63-a417-4fa4-afc1-813a7d3920bb)'
scriptType: 'bash'
scriptLocation: 'inlineScript'
inlineScript: |
az container create \
--name ibrahims \
-g ibbus-container-RG \
--image $(containerRegistry)/$(imageRepository):$(tag) \
--registry-login-server $(containerRegistry) \
--registry-username ibrahims \
--registry-password lxkaWa1MtCG3Li0M8ZPDaVJmFzsj9Kwf79B5UaLwGh+ACRBJQQS9 \
--dns-name-label aci-demo-ibrahimsi

Finally check the URL

Thank you 🙏 for taking the time to read our blog.

--

--

Always learning

கற்றுக் கொள்ளும் மாணவன்...