Lesson 4 — Beginner

Introduction to Docker for Beginners

DevOpsDockerBeginnerTutorial

"It works on my laptop" is the oldest joke in software — and the most expensive when production crashes. Docker fixes that by packing your application and everything it needs into a box that runs the same on your PC, your professor's Mac, and an Azure server.

What Is Docker?

Docker is a platform for building and running containers. A container is an isolated process with its own filesystem — not a full virtual computer, but a neat package with your app inside.

Analogy: shipping containers revolutionized global trade because every crane and ship handles the same box. Docker does that for software — standard packaging any cloud can lift.

Why Do We Need Docker?

Different machines have different .NET versions, Node paths, or missing fonts. Docker bundles the runtime so "version 8.0.4" travels with your app.

Teams use Docker to:

  • Develop locally in the same environment as production.
  • Ship identical images to staging and live servers.
  • Scale by running multiple container copies behind a load balancer.

Step-by-Step: Run Your First Container

Step 1: Install Docker Desktop.

Step 2: Pull a public image and run it:

docker pull nginx:alpine
docker run -d -p 8080:80 --name my-web nginx:alpine

Step 3: Open http://localhost:8080 — you just hosted a web server in a container.

Step 4: List running containers and stop when done:

docker ps
docker stop my-web

Real-World Example

A .NET API team builds one Docker image in CI. The same image runs in dev, QA, and production. When a memory leak appears in QA, they know production has the same bits — no "maybe someone installed a different patch" mystery.

Common Misconceptions

"Docker is a virtual machine." VMs emulate hardware; containers share the host OS kernel and start in seconds.

"Containers are always secure." Isolation helps, but misconfigured images still leak secrets. Scan images and avoid running as root.

Your First Dockerfile

A Dockerfile is a recipe listing steps to build an image. For a simple .NET API:

# Dockerfile (conceptual)
FROM mcr.microsoft.com/dotnet/aspnet:8.0
WORKDIR /app
COPY publish/ .
ENTRYPOINT ["dotnet", "MyApi.dll"]

Build and run your custom image:

docker build -t my-api:1.0 .
docker run -d -p 5000:8080 my-api:1.0

Now your API runs identically on any machine with Docker — no "install .NET 8 first" arguments during demo day.

Docker Compose for Multi-Container Apps

Real apps often need a database plus an API. Docker Compose starts multiple containers with one command — like ordering a combo meal instead of separate items. You define services in docker-compose.yml and run docker compose up. Perfect for local development before cloud deployment.

Docker Volumes for Data

Containers are ephemeral — delete one and internal files vanish. Volumes persist database files outside the container lifecycle. Mount a volume for PostgreSQL data so restarting the container does not wipe student records.

docker run -d -v pgdata:/var/lib/postgresql/data postgres:16

Think of volumes as external hard drives the container plugs into — unplug the container, data stays on the drive.

When learning Docker, practice cleaning up unused resources weekly. Run docker system prune carefully to remove dangling images and free disk space on student laptops that fill up fast after dozens of build attempts. Document which containers must stay running so you do not delete your database volume by accident during cleanup.

Local Dev vs Production Parity

Many teams run databases in Docker locally while deploying APIs to Azure App Service in the cloud. The API container image built in CI should mirror production dependencies — same base image tag, same environment variable names. Drift between laptop Docker and cloud runtime causes the classic 'passed locally, failed in prod' story.

Try dockerizing your semester project API even if deployment stays manual initially. The Dockerfile becomes living documentation of runtime requirements — future teammates know exactly which ports, frameworks, and files the app expects without interrogating you on WhatsApp.

Summary

Docker turns "works on my machine" into "works everywhere." Learn pull, run, build, and Dockerfile basics — they appear in nearly every modern DevOps job posting.

Frequently Asked Questions

A lightweight package that includes your app plus everything it needs to run — code, runtime, libraries — isolated from other apps.

A read-only template used to create containers — like a cookie cutter for running app instances.

Docker Desktop runs on Windows and Mac too, using a small Linux VM under the hood.

A text recipe that tells Docker how to build your image step by step.

Docker Desktop is free for personal and small business use; check current licensing for large enterprises.

Servers drift — different patches, missing libraries. Containers stay consistent.

Key Takeaways

  • Docker packages apps with their dependencies into portable containers.
  • Images are templates; containers are running instances.
  • Dockerfile defines how to build an image reproducibly.
  • Containers start fast and use less resources than full virtual machines.
  • Think shipping containers — same box, any port, predictable contents.

Suggested Next Reads

Share: LinkedIn Facebook X

Need help implementing this in your organization?

Contact Emerrank Consultancy