Last updated: May 2026
Azure ContainersBeginnerAZ-204⏱ 11 min read

Docker on Azure

Docker is the world's most popular container runtime — the tool used to build, run, and manage containers. On Azure, Docker underpins every container service: Container Registry stores Docker images, Container Instances runs Docker containers directly, and AKS orchestrates them at scale. Understanding Docker is essential before working with any Azure container service.

What you'll learn Essential Docker commands · Building and tagging images · Pushing to Azure Container Registry · Running containers locally · Port mapping and environment variables · Docker Compose for multi-container apps · Docker on Azure VMs · Multi-stage builds

Essential Docker Commands

Docker CLIEssential Docker commands
# Build an image from Dockerfile in current directory
docker build -t myapp:v1 .

# List local images
docker images

# Run a container (detached, port mapping)
docker run -d -p 8080:3000 --name mycontainer myapp:v1

# List running containers
docker ps

# List all containers (including stopped)
docker ps -a

# View container logs
docker logs mycontainer

# Execute command inside running container
docker exec -it mycontainer /bin/sh

# Stop a container
docker stop mycontainer

# Remove a container
docker rm mycontainer

# Remove an image
docker rmi myapp:v1

# Pull image from registry
docker pull nginx:latest

Building and Tagging Images

Image tags follow the format: registry/repository:tag

Docker CLIBuild and tag for Azure Container Registry
# Build with a tag
docker build -t myapp:v1.0.0 .

# Tag for Azure Container Registry
docker tag myapp:v1.0.0 myregistry.azurecr.io/myapp:v1.0.0

# Also tag as latest
docker tag myapp:v1.0.0 myregistry.azurecr.io/myapp:latest

Pushing to Azure Container Registry

Azure CLI + DockerLogin to ACR and push image
# Login to Azure Container Registry
az acr login --name myregistry

# Push image to ACR
docker push myregistry.azurecr.io/myapp:v1.0.0
docker push myregistry.azurecr.io/myapp:latest

# Or use ACR build (builds in Azure — no local Docker needed)
az acr build \
  --registry myregistry \
  --image myapp:v1.0.0 \
  --file Dockerfile .
💡
ACR Build vs Local Build az acr build sends your source code to Azure and builds the image there — no Docker installed locally required. Perfect for CI/CD pipelines and cloud shell workflows.

Running Containers

Docker CLIRunning containers with options
# Run with port mapping (host:container)
docker run -p 8080:3000 myapp:v1

# Run detached (background)
docker run -d -p 8080:3000 myapp:v1

# Run with environment variables
docker run -d \
  -p 8080:3000 \
  -e NODE_ENV=production \
  -e DATABASE_URL=mongodb://localhost/mydb \
  myapp:v1

# Run with volume mount (persist data)
docker run -d \
  -p 8080:3000 \
  -v /host/data:/app/data \
  myapp:v1

# Run and remove when stopped
docker run --rm -p 8080:3000 myapp:v1

Docker Compose

Docker Compose defines and runs multi-container applications. A single docker-compose.yml file describes all services, networks, and volumes:

YAMLdocker-compose.yml — web app + database
version: '3.8'
services:
  web:
    build: .
    ports:
      - "8080:3000"
    environment:
      - DATABASE_URL=mongodb://db:27017/myapp
    depends_on:
      - db

  db:
    image: mongo:6
    volumes:
      - mongo-data:/data/db
    ports:
      - "27017:27017"

volumes:
  mongo-data:
Docker CLIDocker Compose commands
# Start all services
docker compose up -d

# View logs for all services
docker compose logs -f

# Stop all services
docker compose down

# Stop and remove volumes
docker compose down -v

Multi-Stage Builds

Multi-stage builds produce smaller production images by separating the build environment from the runtime environment:

DockerfileMulti-stage build — build then copy
# Stage 1: Build
FROM node:20 AS builder
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build

# Stage 2: Production — only copy built output
FROM node:20-alpine AS production
WORKDIR /app
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/node_modules ./node_modules
EXPOSE 3000
CMD ["node", "dist/server.js"]
💡
AZ-204 Exam Tip Know that docker build creates an image, docker run starts a container, docker push uploads to a registry. Know that -p host:container maps ports. Know that az acr build builds directly in Azure. Know that multi-stage builds reduce final image size.
📝 Practice Questions
Click an option to check your answer.
Q1. What does the command docker run -d -p 8080:3000 myapp:v1 do?
A — Runs the container in the foreground and maps port 3000 to host port 8080
B — Runs the container in the background and maps host port 8080 to container port 3000
C — Runs the container detached and maps container port 8080 to host port 3000
D — Builds a new image from the Dockerfile and runs it
Q2. What is the advantage of az acr build over docker build?
A — Builds the image in Azure — no Docker installation required locally
B — Produces smaller images than local docker build
C — Supports a different Dockerfile syntax with more features
D — Images built with az acr build only run on Azure
Q3. What is the purpose of multi-stage Docker builds?
A — To speed up the build process by running stages in parallel
B — To produce smaller production images by separating build tools from runtime
C — To scan images for vulnerabilities during the build process
D — To build different images for different environments simultaneously
Q4. What does Docker Compose do?
A — Orchestrates containers across multiple hosts
B — Defines and runs multi-container applications on a single host from a YAML file
C — Builds container images automatically without a Dockerfile
D — Stores and manages container images in a registry
Q5. How do you pass an environment variable to a Docker container at runtime?
A — Using the -e flag: docker run -e KEY=VALUE myapp:v1
B — Rebuilding the image with the variable hardcoded in the Dockerfile
C — Using the -p flag: docker run -p KEY=VALUE myapp:v1
D — Running docker exec after the container starts to set variables
Comments
Disclaimer: RedKite Cloud is an independent educational resource and is not affiliated with Microsoft Corporation.