๐Ÿ‘ค
๐Ÿณ Module 0 โ€ข 6 Labs โ€ข Est. 45 min โ€ข Beginner

Docker Fundamentals

Master the basics of containerization. Before learning Kubernetes, you must understand how Docker builds, ships, and runs containers.

Containers vs Virtual Machines

A Virtual Machine (VM) includes a full operating system (Guest OS), which is resource-heavy. A Container is just an isolated process running on the host OS. Containers share the host OS kernel, making them lightweight, extremely fast to start, and highly portable.

graph TD; subgraph Virtual Machines HW1[Infrastructure] --> HYP[Hypervisor] HYP --> VM1[VM 1: Libs + Apps + Guest OS] HYP --> VM2[VM 2: Libs + Apps + Guest OS] end subgraph Containers HW2[Infrastructure] --> OS[Host OS] OS --> DE[Container Engine] DE --> C1[Container 1: Libs + App] DE --> C2[Container 2: Libs + App] end

Core Concepts

  • Image: A read-only template with instructions for creating a Docker container. It contains the OS libraries, dependencies, and your application code.
  • Container: A runnable instance of an image. You can create, start, stop, move, or delete a container.
  • Registry: A storage and distribution system for named Docker images. (e.g., Docker Hub, AWS ECR).
  • Dockerfile: A text document that contains all the commands a user could call on the command line to assemble an image.

The Dockerfile

A Dockerfile tells Docker how to build an image layer by layer.

Dockerfile
# Use the official Node.js image as base
FROM node:18-alpine

# Set the working directory inside the container
WORKDIR /app

# Copy package.json and install dependencies
COPY package*.json ./
RUN npm install

# Copy the rest of the application code
COPY . .

# Expose the port the app runs on
EXPOSE 3000

# Command to run the application
CMD ["npm", "start"]

Volumes and Networking

Because containers are ephemeral (temporary), any data written inside a container is lost when it stops. Docker Volumes allow you to persist data outside the container lifecycle.

Docker Networks allow containers to communicate with each other securely, isolated from the host network.

โ–ถ Terminal Simulator
โ–ฒ
K8s.Learn Simulator connected.
Type 'help' for available commands.
root@k8s-master:~#