The foundation of modern microservices starts with isolated, lightweight environments
Containers are the standard way to run microservices reliably and consistently.
They let you package your app and all its dependencies into a single, lightweight unit and run it anywhere.
⚙️ Why Containers?
- 🚀 Fast startup 
 No full OS needed like virtual machines. Containers boot in seconds.
- 🧳 Portable 
 Build once and run anywhere: on a laptop, in the cloud or in CI pipelines.
- 🧱 Isolated 
 Each container has its own filesystem, environment and runtime.
- 🔧 Customizable stacks 
 Mix .NET, Node.js, Java, Python and even legacy systems side by side.
- 💡 Better resource usage 
 Share the host OS kernel without duplicating entire machines.
🧰 Docker in a Nutshell
Docker is the most popular container engine. Here is what it offers:
| Concept | Description | 
|---|---|
| 🧪 Image | Snapshot of your app and its environment | 
| 📦 Container | A running instance of an image | 
| 🗂 Registry | A place to store or pull container images (like Docker Hub) | 
| 🧱 Layering | Images can be built on top of other images | 
| 📄 Dockerfile | Script that defines how to build your image | 
🔍 Example: Dockerfile for ASP.NET Core
# Use Microsoft's base image
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
# Build stage
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["MyApp/MyApp.csproj", "MyApp/"]
RUN dotnet restore "MyApp/MyApp.csproj"
COPY . .
WORKDIR "/src/MyApp"
RUN dotnet build -c Release -o /app/build
# Publish stage
FROM build AS publish
RUN dotnet publish -c Release -o /app/publish
# Final image
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "MyApp.dll"]
This setup:
- Builds your app in a clean environment 
- Publishes only the needed output 
- Runs it on a minimal runtime image 
⚙️ Docker Compose Example
If you need to run multiple services together use Docker Compose:
version: "3.4"
services:
  web:
    image: myapp
    ports:
      - "8080:80"
  redis:
    image: redis:latest
Compose lets you:
- Run and connect multiple containers such as your app and a database 
- Map internal and external ports 
- Use shared volumes and networks 
🧪 Local Dev with Docker in Visual Studio
Visual Studio has built-in Docker support:
- Right-click your project, select Add, then Container Orchestrator Support 
- Choose Docker Compose to manage multiple containers 
- Visual Studio generates a - Dockerfileand a- docker-compose.ymlfor you
- Press F5 to run your app in a container 
Make sure Docker Desktop is running and the whale icon is visible in your taskbar.
Containers make your microservices fast, portable and production-ready.
Once your services are containerized, you can move on to orchestration tools such as Kubernetes or Azure Container Apps.