Beginner 🔥 30-Minute Deep Dive

🐳 Docker Basics

Package your app so it runs the same everywhere. A complete beginner guide with jokes, install steps, and a real project.

30 minutes Hands-On Included Real Project DevOps Jokes Inside
Start reading to track your progress
😂
DevOps Joke #1:

Why did the developer quit his job? Because he didn't get arrays. But then he found Docker and said: "Now my code works on everyone's machine. Even my grandma's!"

1 📖 What is Docker? (Simple Words)

Docker is a tool that puts your app and everything it needs into a container.

A container is like a small lunchbox. Inside the box:

  • Your app
  • The right version of .NET
  • All the settings and libraries

Because everything is inside the box, the app works the same on your laptop, on the test server, and in the cloud.

💡 Think of it like this:
Imagine you move to a new house. Instead of packing everything separately, you pack one box with everything you need. Wherever you go, the box works the same. Docker is that box for your app.

2 ⚖️ Container vs Virtual Machine

Many people confuse containers with virtual machines. They are very different.

Feature Virtual Machine (VM) Docker Container
SizeGigabytes (GB)Megabytes (MB)
Startup timeMinutesSeconds
Operating SystemFull OS insideShares host OS
Resource useHeavyLight
SpeedSlow 🐢Fast 🐇

Simple rule: Use Docker for quick and cheap packaging. Use VMs when you need full separation.

😄
DevOps Joke #2:

A developer says: "It works on my machine!"
A DevOps engineer replies: "Then we'll ship your machine to the customer."
Docker: "Hold my container." 🐳

3 🤔 Why Use Docker?

Works Everywhere
Laptop, server, cloud — same result.
No "Works On My Machine"
Goodbye, version problems.
Fast
Starts in seconds, not minutes.
Small
Less disk, less RAM, more apps per server.
Easy to Share
Send a Dockerfile — anyone can run it.
Isolated
One crash does not kill the others.

4 🔑 Key Docker Words

WordSimple Meaning
ImageA recipe. Instructions to create a container.
ContainerA running instance of an image. Like a running app.
DockerfileA text file with instructions to build an image.
VolumeA folder shared between your PC and the container. Data survives.
PortA door. Users reach the app through a port.
RegistryA place to store images (like Docker Hub).
Docker HubA public registry where people share images.

5 🌍 Real Client Example: The Restaurant Menu

Client: A family restaurant in Hamilton, Ontario. They want an online menu so customers can see dishes and prices.

Problem: The developer built the app on their laptop — works perfectly. But on the server, it crashes. Server has .NET 6, laptop has .NET 8. Same code, different result. The classic "works on my machine" problem.

Step 1: Write a Dockerfile

"Use .NET 8. Copy the app. Build. Run." Now we have a recipe.

Step 2: Build the image

Run docker build -t menu-app .

Step 3: Run the container

Run docker run -p 8080:80 menu-app — starts in seconds.

🎉 The Result
  • Runs the same on laptop, test server, and cloud.
  • No more version problems.
  • Menu updates in seconds.
  • Deployment: 1 minute (was 1 hour).

6 💻 How to Install Docker (Step by Step)

Follow these steps exactly. Do not skip any.

🪟 Windows
  1. Go to docker.com/products/docker-desktop.
  2. Click Download for Windows.
  3. Run the installer (Docker Desktop Installer.exe).
  4. During setup, keep "Use WSL 2" checked (recommended).
  5. Click Ok and wait for install to finish.
  6. Restart your computer when asked.
  7. Open Docker Desktop from the Start Menu.
  8. Accept the terms. Wait for the whale icon 🐳 in the taskbar.
  9. Done. Docker is running.
🍎 macOS
  1. Download Docker Desktop for Mac.
  2. Choose Apple Silicon or Intel based on your Mac.
  3. Open the .dmg file.
  4. Drag the Docker icon into Applications.
  5. Open Docker from Applications.
  6. Accept the terms and give permission.
  7. Wait for the whale icon 🐳 in the menu bar.
🐧 Linux (Ubuntu)
  1. Open a terminal.
  2. Run: sudo apt update
  3. Run: sudo apt install docker.io -y
  4. Run: sudo systemctl start docker
  5. Run: sudo systemctl enable docker
  6. To run docker without sudo: sudo usermod -aG docker $USER
  7. Log out and log back in.
✅ Verify the installation:
Open a terminal and run: docker --version
You should see something like Docker version 24.0.0. If you do, you are ready!
🤣
DevOps Joke #3:

Docker walked into a bar and asked for a drink. The bartender said: "We don't serve containers here."
Docker replied: "That's fine, I'm isolated anyway." 🐳

7 ✍️ Your First Dockerfile (Line by Line)

A Dockerfile is a text file with instructions. Here is one for a .NET app:

# Use the official .NET SDK image to build the app
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /app

# Copy the project file and restore dependencies
COPY *.csproj ./
RUN dotnet restore

# Copy the rest of the code and build it
COPY . ./
RUN dotnet publish -c Release -o out

# Use a smaller runtime image for the final container
FROM mcr.microsoft.com/dotnet/aspnet:8.0
WORKDIR /app
COPY --from=build /app/out .

# Tell Docker what command to run
ENTRYPOINT ["dotnet", "MyApp.dll"]
📘 What Each Line Does
LineWhat It Does
FROM ... AS buildStarts from the SDK image. Names this stage "build".
WORKDIR /appSets the working folder inside the container.
COPY *.csproj ./Copies the project file into the container.
RUN dotnet restoreDownloads NuGet packages.
COPY . ./Copies your source code.
RUN dotnet publish -c Release -o outBuilds the app in Release mode.
FROM ...aspnet:8.0New, smaller image for runtime.
COPY --from=build /app/out .Copies only the built files.
ENTRYPOINT ["dotnet", "MyApp.dll"]Command to run when the container starts.
💡 Why two FROM lines?
"build" is big (~1 GB). "runtime" is small (~200 MB). This is a multi-stage build — smaller, faster, safer.

8 ⌨️ Basic Docker Commands

CommandWhat It Does
docker build -t myapp .Builds an image named "myapp".
docker run -p 8080:80 myappRuns and maps port 8080 → 80.
docker psShows running containers.
docker ps -aShows all containers.
docker stop <id>Stops a container.
docker rm <id>Deletes a stopped container.
docker imagesLists all images.
docker rmi <id>Deletes an image.
docker logs <id>Shows logs (great for debugging).
docker exec -it <id> bashOpens a terminal inside a container.

9 🛠️ Hands-On Practice (Do This Now)

Step 1: Verify installation

Run docker --version. Expect Docker version 24.0.0 or similar.

Step 2: Run your first container

Run docker run hello-world. Docker downloads a tiny image and prints a message.

Step 3: Run a real web server

Run docker run -d -p 8080:80 nginx. Open http://localhost:8080 in a browser. Stop it with docker stop <id>.

Step 4: Build your own image

Create a Dockerfile (from Section 7). Put your .NET project next to it. Run docker build -t my-first-app ..

Step 5: Run your app

Run docker run -d -p 8080:80 my-first-app. Open the browser. Your app is live!

😆
DevOps Joke #4:

How many DevOps engineers does it take to change a light bulb?
None. They automate the light bulb replacement and add a monitoring dashboard. 💡📊

10 🔧 Common Problems and Fixes

ProblemCauseFix
Port is in useAnother app uses it.Change the port: -p 8081:80
Container stops instantlyApp crashed on start.Check logs: docker logs <id>
"docker: command not found"Not installed.Install Docker Desktop.
Build is slowRebuilding too much.Add a .dockerignore.
Data disappearsContainer data is temporary.Use a volume: -v
🎓 Final Project

11 🏗️ Build a Real Docker Project (End-to-End)

Build, containerize, run, and share a real ASP.NET Core app. Follow this exactly and you will have a working Docker project.

🎯 What You Will Build

A simple "Hello World" ASP.NET Core web app, packaged in a Docker container, running on your computer.

📁 Project Folder

Create a folder called HelloDocker anywhere on your PC.

🛠️ Step 1: Create the App

Open a terminal in that folder and run:

dotnet new web -n HelloDocker
cd HelloDocker
🛠️ Step 2: Change the Program.cs

Open Program.cs. Replace everything with:

var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();

app.MapGet("/", () => "Hello from Docker! 🐳 My first container is alive!");

app.Run();
🛠️ Step 3: Add a Dockerfile

In the HelloDocker folder, create a new file called Dockerfile (no extension). Paste:

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /app
COPY *.csproj ./
RUN dotnet restore
COPY . ./
RUN dotnet publish -c Release -o out

FROM mcr.microsoft.com/dotnet/aspnet:8.0
WORKDIR /app
COPY --from=build /app/out .
ENTRYPOINT ["dotnet", "HelloDocker.dll"]
🛠️ Step 4: Add .dockerignore

Create a file called .dockerignore with:

bin/
obj/
*.user
*.suo

This keeps the image small and build fast.

🛠️ Step 5: Build the Image

In the same folder, run:

docker build -t hello-docker .

Wait for it to finish. The first time may take 1–2 minutes.

🛠️ Step 6: Run the Container
docker run -d -p 8080:80 --name my-hello-app hello-docker

This runs the container in the background.

🛠️ Step 7: Test It

Open your browser and go to:

http://localhost:8080

You should see: "Hello from Docker! 🐳 My first container is alive!"

🛠️ Step 8: Manage the Container
docker ps                # see it running
docker logs my-hello-app # see logs
docker stop my-hello-app # stop it
docker rm my-hello-app   # delete it
🛠️ Step 9: Share It (Bonus)

To share your image with others, push it to Docker Hub:

docker login
docker tag hello-docker YOUR_DOCKERHUB_USERNAME/hello-docker
docker push YOUR_DOCKERHUB_USERNAME/hello-docker

Anyone in the world can now run:

docker run -p 8080:80 YOUR_DOCKERHUB_USERNAME/hello-docker
🎉 Congratulations!

You just built a real Docker project. You:

  • Wrote a Dockerfile
  • Built a Docker image
  • Ran the container
  • Tested it in the browser
  • Shared it with the world

12 ✅ What You Learned

  • Docker puts your app into a container.
  • Containers run the same everywhere.
  • Containers are smaller and faster than VMs.
  • A Dockerfile tells Docker how to build an image.
  • You use docker build, docker run, docker ps.
  • Multi-stage builds keep your image small.
  • Volumes keep data safe.
  • You built a real Docker project from scratch!

13 🧠 Test Yourself

  1. What is a Docker container?
  2. How is a container different from a VM?
  3. What does a Dockerfile do?
  4. Difference between an image and a container?
  5. What does docker ps do?
  6. Why use volumes?
  1. A small box with your app and everything it needs.
  2. Containers are smaller, faster, share the host OS. VMs are bigger, slower, own OS.
  3. A text file with instructions to build an image.
  4. Image = recipe (static). Container = running app (dynamic).
  5. Lists running containers.
  6. Volumes keep data safe after the container stops.

🚀 What's Next?

  • CI/CD Pipelines — Automate build and deploy.
  • Kubernetes — Manage many containers at once.
  • Docker Compose — Run an app + database together.