Mastering the Command Line: A Developer's Cheat Sheet

Essential shell commands every developer should know by heart

Posted by Hüseyin Sekmenoğlu on January 09, 2023 Tooling & Productivity

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:

  1. Builds your app in a clean environment

  2. Publishes only the needed output

  3. 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 Dockerfile and a docker-compose.yml for 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.