Container Basics

What is Containerization?

Containerization is a lightweight, scalable, and efficient approach to packaging and running applications along with their dependencies in isolated environments known as containers. Unlike virtual machines, containers share the host operating system’s kernel, making them lightweight and fast to start.

image.png

Docker Fundamentals

Docker is the most widely adopted container platform. Understanding Docker includes grasping these core concepts:

# 1. Choose a small, maintained base image
FROM node:20-alpine AS build

# 2. Set working directory
WORKDIR /app

# 3. Cache dependency install
COPY package.json yarn.lock ./
RUN yarn install --frozen-lockfile

# 4. Copy source & build
COPY . .
RUN yarn build

# 5. Create lean runtime image
FROM node:20-alpine AS runtime
WORKDIR /app
COPY --from=build /app/dist ./dist
COPY --from=build /app/node_modules ./node_modules

# 6. Define entrypoint
ENTRYPOINT ["node", "dist/server.js"]

Virtualization Concepts

What is Virtualization?

Virtualization refers to the creation of virtual environments (Virtual Machines or VMs) that simulate dedicated hardware, running full operating systems and applications on top of a hypervisor. It allows multiple operating systems to run concurrently on a single physical host.

Types of Virtualization

image.png

Comparing Containers and Virtualization