0% found this document useful (0 votes)
3 views11 pages

Unit 1 - Short

The document provides an overview of containerization, emphasizing its role in creating consistent application environments across development, QA, and production. It introduces Docker as a platform for managing containers, detailing installation, commands, and orchestration tools like Docker Compose and Docker Swarm. The advantages and drawbacks of containerization are discussed, highlighting its efficiency and portability while noting security risks and complexity.

Uploaded by

auric266
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views11 pages

Unit 1 - Short

The document provides an overview of containerization, emphasizing its role in creating consistent application environments across development, QA, and production. It introduces Docker as a platform for managing containers, detailing installation, commands, and orchestration tools like Docker Compose and Docker Swarm. The advantages and drawbacks of containerization are discussed, highlighting its efficiency and portability while noting security risks and complexity.

Uploaded by

auric266
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Unit 1:

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.

Different Execution Environments:

1. Developer Environment:

o Developers write and test code on their local machines.

o Local machines may differ from production, which can cause inconsistencies in how
the app runs.

2. QA (Quality Assurance) Environment:

o After development, the code is tested here for bugs or issues.

o QA environments can differ from both development and production, causing


discrepancies.

3. Production Environment:

o The final environment where the app is deployed for actual users.

o It needs to be stable and optimized.

Problem: The code works on a developer's machine but doesn't always work the same in QA or
production due to environment differences.

Overcoming Issues with Different Environments:

Virtual Machines (VMs):

 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:

 Imagine transporting goods (applications) in trucks (VMs).

 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.

Machines, Images, and Containers:

1. Machine:

o A physical or virtual server where software runs.

2. Images:

o An image is a blueprint that defines what will be inside a container (software,


dependencies, libraries, etc.).

o Think of it like a recipe or mold for creating containers.

3. Containers:

o Containers are instances created from images.

o Each container runs a specific application or service.

Difference from Virtual Machines (VMs):

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:

 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 (Linux Containers):

 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.

5. Faster Development: Developers can quickly set up environments, speeding up the


development cycle.

Drawbacks of Containerization:

1. Security Risks: Containers share the host OS kernel, which can pose security risks if not
properly managed.

2. Limited Isolation: Containers don't provide as strong isolation as VMs.

3. Complexity: Orchestrating and managing large numbers of containers can be complex.

4. Persistent Data: Managing data in containers can be tricky since containers are stateless by
design.

Summary:

 Containerization is a technology that isolates applications in lightweight environments called


containers.

 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.

Installing Docker Engine & Setup:

1. Steps to Install Docker:

o Update your system: sudo apt-get update

o Install prerequisites: sudo apt-get install apt-transport-https ca-certificates curl


software-properties-common

o Add Docker’s GPG key: curl -fsSL https://download.docker.com/linux/ubuntu/gpg |


sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

o Add Docker repository:

bash

Copy code

echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg]


https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee
/etc/apt/sources.list.d/docker.list > /dev/null

o Install Docker: sudo apt-get install docker-ce

o Verify installation: docker --version

2. Docker Setup:

o Ensure the Docker service is running: sudo systemctl start docker

o Test by running: sudo docker run hello-world

Working with Docker Registry:

 Docker Registry: A storage system for Docker images.

o Public Registry: Docker Hub (default registry).

o Private Registry: For internal use within an organization.

 Use docker pull to download images and docker push to upload images.
Handling Docker Containers:

Steps to Build and Run a Docker Container:

1. Pull a base image:


Example: docker pull ubuntu

2. Run a container:
Example: docker run -it ubuntu bash
(Starts an interactive shell in the Ubuntu container.)

3. List running containers:


docker ps

4. Stop a container:
docker stop <container_id>

5. Remove a container:
docker rm <container_id>

Docker Syntax & Commands:

1. Basic Commands:

o List images: docker images

o Run a container: docker run <image_name>

o Stop container: docker stop <container_id>

o Remove container: docker rm <container_id>

o List containers: docker ps (running), docker ps -a (all)

2. Dockerfile Commands:

o FROM: Base image (e.g., FROM ubuntu).

o RUN: Execute a command (e.g., RUN apt-get update).

o COPY: Copy files into the container.

o CMD: Default command to run in the container.

Docker Image Management:

 Docker Image: A template used to create containers.

 Commands:

o List images: docker images

o Remove image: docker rmi <image_id>


o Tag image: docker tag <image_id> <new_name:tag>

o Build image from Dockerfile: docker build -t <image_name> .

Dockerfiles:

1. What is a Dockerfile?

o A text file containing instructions to build a Docker image.

2. Steps to Build Custom Image:

o Create a file named Dockerfile.

o Add instructions like:

sql

Copy code

FROM ubuntu

RUN apt-get update

COPY . /app

CMD ["bash"]

o Build the image: docker build -t custom_image .

Understanding Docker Hub:

 Docker Hub: A public registry where Docker images are stored and shared.

 Commands:

o Pull an image: docker pull <image_name>

o Push an image: docker push <image_name>

Docker Networking:

1. Overview:

o Docker provides networking options for containers to communicate.

2. Types of Docker Networks:

o Bridge: Default network for standalone containers.

o Host: Container shares the host's network stack.

o None: No network for the container.

3. Commands:
o List networks: docker network ls

o Create network: docker network create <network_name>

o Connect container to network: docker network connect <network_name>


<container_name>

Understanding Services in Containers:

 A service is a way to scale containers across multiple hosts.

 Used with orchestration tools like Docker Swarm.

Sharing Data with Containers:

1. Volumes: Persistent storage for containers.

o Create a volume: docker volume create <volume_name>

o Attach volume: docker run -v <volume_name>:/data <image_name>

2. Bind Mounts: Link specific directories on the host to the container.

Building a Private Docker Infrastructure:

1. Set up a private Docker registry:

o Run a registry container: docker run -d -p 5000:5000 --name registry registry:2

o Push images to the private registry.

2. Access the private registry:

o Pull: docker pull localhost:5000/<image_name>

o Push: docker push localhost:5000/<image_name>

Securing Docker Containers:

1. Use Minimal Images: Reduce vulnerabilities by using minimal base images (e.g., alpine).

2. Apply Resource Limits:

o Limit CPU: docker run --cpus="1" <image_name>

o Limit memory: docker run -m 512m <image_name>

3. Use Non-Root Users:

o Run containers as non-root users to reduce risks.

4. Regular Updates: Keep Docker Engine and images up to date.


Unit 3:

Simple Notes on Docker Orchestration and Related Topics

1. Orchestration of Docker Containers using Docker Compose:

 Docker Compose is a tool used to define and manage multi-container applications.

 It uses a docker-compose.yml file to configure services, networks, and volumes.

Steps to Use Docker Compose:

1. Install Docker Compose:

o Ensure Docker is installed.

o Verify with: docker-compose --version.

2. Create docker-compose.yml: Example:

yaml

Copy code

version: '3'

services:

web:

image: nginx

ports:

- "8080:80"

db:

image: mysql

environment:

MYSQL_ROOT_PASSWORD: root

3. Run Docker Compose:

o Start services: docker-compose up

o Stop services: docker-compose down

Why Use Docker Compose?

 Simplifies managing multiple containers.

 Enables easy service linking, networking, and scaling.

2. Cluster Management using Docker Swarm:


 Docker Swarm: A native clustering and orchestration tool for Docker containers.

 Cluster: A group of Docker hosts working together as a single system.

Key Features:

 High availability.

 Load balancing.

 Service scaling.

Steps to Set Up Docker Swarm:

1. Initialize Swarm:

o docker swarm init

2. Add Nodes:

o On other hosts, use the token generated during initialization:


docker swarm join --token <token> <manager_ip>:2377

3. Deploy a Service:

o docker service create --name web --replicas 3 -p 80:80 nginx (Creates 3 replicas of an
NGINX container.)

4. Monitor the Cluster:

o docker node ls (list nodes)

o docker service ls (list services)

3. Debugging Containers:

1. Check Logs:

o docker logs <container_id> (view logs for a container).

2. Inspect a Container:

o docker inspect <container_id> (get detailed configuration and state).

3. Enter a Running Container:

o docker exec -it <container_id> /bin/bash (interactive shell access).

4. Monitor Resource Usage:

o docker stats (real-time performance metrics).

4. Docker & DevOps:

 Role of Docker in DevOps:


o Docker integrates well with CI/CD pipelines for building, testing, and deploying
applications.

o Ensures consistency across development, testing, and production environments.

 Common Docker Use Cases in DevOps:

o Build lightweight, portable images.

o Automate testing with containers.

o Deploy scalable applications with orchestration tools.

5. Reason for Using Orchestration Tools:

 Orchestration manages multiple containers efficiently, ensuring high availability and


scalability.

 Why Orchestration is Necessary:

o Automates deployment, scaling, and management of containers.

o Simplifies communication between containers.

o Provides load balancing and failover.

o Makes managing large-scale applications easier.

6. Examples of Orchestration Tools:

Docker Swarm:

 Built into Docker.

 Lightweight and simple to use.

 Suitable for small to medium-sized clusters.

Kubernetes (K8s):

 More powerful and feature-rich than Docker Swarm.

 Offers advanced features like auto-scaling, rolling updates, and health checks.

 Best for large-scale applications and enterprise-level deployments.

7. Comparison: Docker Swarm vs. Kubernetes:

Feature Docker Swarm Kubernetes

Ease of Use Simple to set up. Complex setup.

Scalability Suitable for smaller clusters. Highly scalable for large clusters.
Feature Docker Swarm Kubernetes

Load Balancing Built-in. Built-in.

Community Support Smaller. Large and active.

Feature Set Limited. Rich feature set.

Summary:

 Docker Compose simplifies multi-container setups for single-host environments.

 Docker Swarm provides lightweight clustering, while Kubernetes handles complex, large-
scale orchestration.

 Orchestration tools automate deployment, scaling, and management, making containerized


applications efficient and reliable.

Let me know if you'd like more details on any specific part!

You might also like