Previous Authentication protocols NTLM, Kerberos Terraform Next

Containerization Overview

Containerization

Containerization is a method of packaging software so it can run reliably across different computing environments. It wraps an application along with its dependencies, libraries, and configuration files into a single unit called a container. These containers are lightweight, portable, and isolated from the host system, making them ideal for consistent deployment across development, testing, and production.

Why use containerization?

  • Portability: Run anywhere—local machine, cloud, or server.
  • Isolation: Each container runs independently.
  • Scalability: Easily replicate containers to handle load.
  • Consistency: No more “works on my machine” issues.

What is Docker

Docker is a popular platform for developing, shipping, and running applications inside containers. It provides tools to create, manage, and orchestrate containers efficiently.

Example: Containerizing a Simple C# "Hello World" Console App

1. Create the C# App

bash
dotnet new console -o HelloWorldApp -n HelloWorld

This creates a folder HelloWorldApp with a Program.cs file that prints "Hello World".

2. Edit Program.cs (optional)

csharp
using System;

namespace HelloWorld
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello from a Docker container!");
        }
    }
}

3. Create a Dockerfile

Inside the HelloWorldApp folder, create a file named Dockerfile:

Dockerfile
# Use official .NET SDK image to build the app
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /app
COPY . .
RUN dotnet publish -c Release -o out

# Use runtime image to run the app
FROM mcr.microsoft.com/dotnet/runtime:8.0
WORKDIR /app
COPY --from=build /app/out .
ENTRYPOINT ["dotnet", "HelloWorld.dll"]

4. Build the Docker Image

bash
docker build -t helloworld-csharp .

5. Run the Container

bash
docker run helloworld-csharp

You should see:

Hello from a Docker container!

Docker commands

🐳 Docker Basics

Command Usage
docker --versionCheck Docker version installed
docker infoDisplay system-wide Docker information
docker helpShow help for Docker CLI

📦 Image Management

CommandUsage
docker build -t <image_name> .Build image from Dockerfile in current directory
docker imagesList all local Docker images
docker rmi <image_name>Remove a Docker image
docker pull <image_name>Download image from Docker Hub
docker push <image_name>Upload image to Docker Hub
docker image pruneRemove unused images

🚀 Container Lifecycle

CommandUsage
docker run <image_name>Run a container from an image
docker run -it <image_name>Run container interactively (e.g., with shell access)
docker run -d <image_name>Run container in detached mode (background)
docker run --name <container_name> <image_name>Assign a name to the container
docker start <container_name>Start a stopped container
docker stop <container_name>Stop a running container
docker restart <container_name>Restart a container
docker rm <container_name>Remove a stopped container
docker psList running containers
docker ps -aList all containers (including stopped)

🔍 Container Interaction

CommandUsage
docker exec -it <container_name> shOpen shell inside running container
docker logs <container_name>View container logs
docker inspect <container_name>View detailed container info
docker attach <container_name>Attach to a running container's output
docker cp <container_name>:<path> <host_path>Copy files from container to host

🌐 Networking

CommandUsage
docker network lsList Docker networks
docker network create <network_name>Create a new network
docker network connect <network_name> <container_name>Connect container to network

📁 Volumes

CommandUsage
docker volume lsList volumes
docker volume create <volume_name>Create a volume
docker volume rm <volume_name>Remove a volume
docker volume inspect <volume_name>View volume details

🧹 Cleanup

CommandUsage
docker system pruneRemove unused containers, networks, images, and volumes
docker container pruneRemove all stopped containers
docker volume pruneRemove all unused volumes

🛠️ Docker Compose (if used)

CommandUsage
docker-compose upStart services defined in docker-compose.yml
docker-compose downStop and remove containers, networks, volumes
docker-compose buildBuild images defined in compose file
docker-compose logsView logs for all services
Back to Index
Previous Authentication protocols NTLM, Kerberos Terraform Next
*