Unit 1 - Short
Unit 1 - Short
Introduction to Containerization:
Containerization is a technology that allows you to package and run applications in a loosely isolated
environment called containers. It ensures that the application runs the same way across different
systems by packaging the application and its dependencies together.
1. Developer Environment:
o Local machines may differ from production, which can cause inconsistencies in how
the app runs.
3. Production Environment:
o The final environment where the app is deployed for actual users.
Problem: The code works on a developer's machine but doesn't always work the same in QA or
production due to environment differences.
VMs are like running an entire separate computer inside your computer.
Each VM has its own operating system (OS) and software, making it heavier and slower.
VMs help run applications in a consistent way across different environments, but they
require more resources (CPU, memory).
Containers:
Containers solve the problem of environment differences by packaging the application with
its dependencies in a lightweight, portable unit.
They share the host system's OS kernel but run isolated from each other.
Containers are lighter than VMs, and they can be started quickly.
Analogy of Transporting Goods:
A truck carries its own engine, fuel, and driver (full OS), which makes it heavy and consumes
a lot of resources.
Instead of trucks, shipping containers (containers) can be used. These containers don't have
their own engines but instead use the engine of the ship (host OS) and are easier to
transport and handle.
1. Machine:
2. Images:
3. Containers:
1. VMs:
o VMs have their own OS and hardware emulation, requiring more resources.
o They are slower to start and consume more CPU and memory.
2. Containers:
o Containers share the host OS kernel, making them lighter and faster.
o They are more efficient, start up quicker, and use fewer resources than VMs.
The chroot system call changes the root directory for a process, making it appear as though
the process is running in a different directory.
This provides some level of isolation, similar to containers, but it is not as strong as modern
container technologies.
FreeBSD Jails:
Jails in FreeBSD are a way to isolate processes into separate environments, similar to
containers.
Each jail has its own file system, network stack, and process space, but all share the same OS
kernel.
LXC is a user-space interface for the Linux kernel, providing lightweight virtualization.
LXC containers allow multiple isolated Linux systems (containers) to run on a single host.
It’s an early form of containerization, providing process isolation with a minimal overhead.
Advantages of Containerization:
1. Portability: Containers can run on any system that supports the container runtime (e.g.,
Docker).
2. Consistency: The app and its dependencies are bundled, ensuring it behaves the same across
environments.
3. Efficiency: Containers are lightweight and start up quickly, using fewer resources than VMs.
4. Scalability: Easily scale applications with container orchestration tools like Kubernetes.
Drawbacks of Containerization:
1. Security Risks: Containers share the host OS kernel, which can pose security risks if not
properly managed.
4. Persistent Data: Managing data in containers can be tricky since containers are stateless by
design.
Summary:
It solves the problem of differing environments across development, QA, and production.
Containers are more efficient than virtual machines and are easier to deploy and scale.
LXC and FreeBSD Jails are early technologies that laid the groundwork for modern
containerization.
Unit 2:
Docker Overview:
Docker is a platform that uses containerization to create, deploy, and run applications in isolated
environments. Containers are lightweight, portable, and efficient.
bash
Copy code
2. Docker Setup:
Use docker pull to download images and docker push to upload images.
Handling Docker Containers:
2. Run a container:
Example: docker run -it ubuntu bash
(Starts an interactive shell in the Ubuntu container.)
4. Stop a container:
docker stop <container_id>
5. Remove a container:
docker rm <container_id>
1. Basic Commands:
2. Dockerfile Commands:
Commands:
Dockerfiles:
1. What is a Dockerfile?
sql
Copy code
FROM ubuntu
COPY . /app
CMD ["bash"]
Docker Hub: A public registry where Docker images are stored and shared.
Commands:
Docker Networking:
1. Overview:
3. Commands:
o List networks: docker network ls
1. Use Minimal Images: Reduce vulnerabilities by using minimal base images (e.g., alpine).
yaml
Copy code
version: '3'
services:
web:
image: nginx
ports:
- "8080:80"
db:
image: mysql
environment:
MYSQL_ROOT_PASSWORD: root
Key Features:
High availability.
Load balancing.
Service scaling.
1. Initialize Swarm:
2. Add Nodes:
3. Deploy a Service:
o docker service create --name web --replicas 3 -p 80:80 nginx (Creates 3 replicas of an
NGINX container.)
3. Debugging Containers:
1. Check Logs:
2. Inspect a Container:
Docker Swarm:
Kubernetes (K8s):
Offers advanced features like auto-scaling, rolling updates, and health checks.
Scalability Suitable for smaller clusters. Highly scalable for large clusters.
Feature Docker Swarm Kubernetes
Summary:
Docker Swarm provides lightweight clustering, while Kubernetes handles complex, large-
scale orchestration.