Containers

Beginner Level

Basic concepts and fundamentals of Docker and Kubernetes for DevOps interviews.

Beginner Level

This section covers fundamental concepts of Docker and Kubernetes, including basic principles, commands, and common practices.

Docker Basics

What is Docker, and why is it used?

Docker is a containerization platform that allows developers to package applications along with their dependencies into a single unit called a container.

  • Why use Docker?
    ✅ Ensures consistent environments across different machines.
    Lightweight & faster than virtual machines.
    Easy scaling of applications in microservices architectures.

What is the difference between Docker and a Virtual Machine (VM)?

FeatureDockerVirtual Machine
IsolationUses containers to isolate appsUses hypervisor to run separate OS instances
PerformanceFaster, lightweightSlower, resource-intensive
Startup TimeMillisecondsMinutes
Use CaseIdeal for microservicesBest for full OS emulation

What is a Docker image?

A Docker image is a read-only template containing everything needed to run an application, including:

  • Source code
  • Libraries & dependencies
  • Configuration files

A container is created from a Docker image using the docker run command.

What is a Docker container?

A Docker container is a running instance of a Docker image. It is:
Lightweight (shares OS kernel)
Isolated (has its own filesystem, network, and process space)
Portable (can run on any system with Docker installed)

How do you create and run a Docker container?

To run a container from an image:

docker run -d --name myapp nginx
  • -d: Run in detached mode (background).
  • --name myapp: Name the container myapp.
  • nginx: Use the nginx image.

What is the purpose of the Dockerfile?

A Dockerfile is a script that contains instructions to build a Docker image.
Example Dockerfile:

FROM node:16
WORKDIR /app
COPY . .
RUN npm install
CMD ["node", "app.js"]
  • FROM: Base image.
  • WORKDIR: Set working directory.
  • COPY: Copy files.
  • RUN: Execute commands (install dependencies).
  • CMD: Define the default command to run.

What are Docker volumes?

Docker volumes store persistent data outside a container's filesystem.

  • Types:
    • Anonymous Volumes: docker run -v /data nginx
    • Named Volumes: docker volume create mydata
    • Bind Mounts: docker run -v /host/path:/container/path nginx

How do you list running Docker containers?

Use the command:

docker ps

To list all containers (including stopped ones):

docker ps -a

What is Docker Compose?

Docker Compose is a tool for defining and running multi-container applications.

  • Example docker-compose.yml:

    version: "3"
    services:
      web:
        image: nginx
        ports:
          - "80:80"
      db:
        image: mysql
        environment:
          MYSQL_ROOT_PASSWORD: root
  • Start with: docker-compose up -d

  • Stop with: docker-compose down

What is the difference between CMD and ENTRYPOINT in Docker?

FeatureCMDENTRYPOINT
PurposeDefault commandFixed executable command
Overridable?YesNo (unless --entrypoint is used)
ExampleCMD ["python", "app.py"]ENTRYPOINT ["nginx", "-g", "daemon off;"]

Kubernetes Basics

What is Kubernetes?

Kubernetes (K8s) is an orchestration platform for managing containerized applications.

  • Features:
    Automated scaling
    Self-healing (restarts failed containers)
    Load balancing
    Rolling updates

What is a Kubernetes Pod?

A Pod is the smallest unit in Kubernetes. It groups one or more containers that share the same network and storage.

What is a Kubernetes Deployment?

A Deployment manages Pod creation and updates.
Example YAML:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-app
spec:
  replicas: 3
  selector:
    matchLabels:
      app: my-app
  template:
    metadata:
      labels:
        app: my-app
    spec:
      containers:
        - name: app
          image: nginx
  • replicas: 3 → Runs 3 instances.
  • matchLabels → Ensures the correct Pods are managed.

What is a Kubernetes Service?

A Service exposes a set of Pods over a network.

  • Types:
    • ClusterIP (default)
    • NodePort (exposes on a fixed port)
    • LoadBalancer (uses cloud provider's load balancer)

📢 Contribute & Stay Updated

💡 Want to contribute?
We welcome contributions! If you have insights, new tools, or improvements, feel free to submit a pull request.

📌 How to Contribute?

  • Read the CONTRIBUTING.md guide.
  • Fix errors, add missing topics, or suggest improvements.
  • Submit a pull request with your updates.

🌍 Community & Support

🔗 GitHub: @NotHarshhaa
📝 Blog: ProDevOpsGuy
💬 Telegram Community: Join Here