Date:
Roll No:
EXPERIMENT NO.10
Aim: To study and implement containerization using docker
Objective: To know the basic differences between Virtual machine and Container. It involves
demonstration of creating, finding, building, installing, and running Linux/Windows application
containers inside a local machine or cloud platform.
Theory:
What is docker?
Docker is a set of platforms as a service (PaaS) products that use the Operating system level
visualization to deliver software in packages called containers. Containers are isolated from one
another and bundle their own software, libraries, and configuration files; they can communicate with
each other through well-defined channels. All containers are run by a single operating system kernel
and therefore use fewer resources than a virtual machine.
Difference between Docker Containers and Virtual Machines
Docker containers and Virtual Machines (VMs) are both technologies that allow you to run multiple
isolated environments on a single physical host, but they differ in how they achieve this isolation, their
architecture, and use cases. Here's a breakdown of the key differences:
1. Architecture
• Virtual Machines (VMs): VMs run a full operating system (OS) with its own kernel on top of
a hypervisor (such as VMware or VirtualBox). The hypervisor manages the VMs and abstracts
the underlying hardware. Each VM has its own OS, including a kernel and user space.
1
• Docker Containers: Containers share the host OS kernel but run in isolated user spaces.
Docker uses container runtimes (like Docker Engine) to isolate the applications and their
dependencies from the host OS and other containers. Containers are more lightweight because
they don’t include their own OS.
2. Resource Efficiency
• VMs: Each VM runs a full OS, so it requires more resources (CPU, memory, disk) because it
includes an OS in addition to the application. This can lead to more overhead.
• Docker Containers: Containers share the host OS kernel, meaning they are more lightweight
and efficient in terms of resource usage. Multiple containers can run on a single system with
lower overhead compared to VMs.
3. Performance
• VMs: Since VMs run a full OS, there is more overhead in terms of CPU, memory, and storage.
They tend to be slower than containers because they need to virtualize hardware and resources.
• Docker Containers: Containers are generally faster and more lightweight because they run
directly on the host OS without the need for a hypervisor or full OS virtualization. This makes
them more efficient in terms of performance.
4. Isolation
• VMs: VMs offer strong isolation because each VM runs its own full OS and has its own
kernel. This means VMs are more isolated from each other, offering better security in some
cases.
• Docker Containers: While containers are isolated from each other, they share the same OS
kernel. This means containers are less isolated compared to VMs and could have potential
security risks if the host OS kernel is compromised.
5. Boot Time
• VMs: VMs generally take longer to boot up because they need to load a full operating system.
• Docker Containers: Containers start much faster since they only need to start the application
processes and share the host OS kernel.
6. Use Cases
• VMs: VMs are better suited for running different operating systems on the same hardware
(e.g., running Windows and Linux on the same machine) or when full isolation is required. They
are often used for legacy applications or workloads that require full OS functionality.
1
• Docker Containers: Containers are ideal for microservices architecture, running stateless
applications, and scenarios where you need to package applications with all their
dependencies. They are commonly used in DevOps pipelines, CI/CD workflows, and
cloudnative applications.
7. Portability
• VMs: VMs are less portable than containers because they are dependent on the hypervisor and
often tied to specific cloud providers or virtualization technologies.
• Docker Containers: Containers are highly portable because they encapsulate the application
and its dependencies. You can run the same container on any platform that supports Docker
(Windows, macOS, Linux, cloud environments, etc.).
8. Size
• VMs: Since each VM includes a full OS, they tend to be large in terms of disk space (several
gigabytes).
• Docker Containers: Containers are much smaller since they only include the application and
its dependencies, without the need for a full OS. This makes them quicker to deploy and less
resource-intensive.
Summary Table:
Feature Virtual Machines (VMs) Docker Containers
Full OS with own kernel on a
Architecture Share host OS kernel, isolated user space
hypervisor
Resource Efficiency More resource-heavy (includes full
Lightweight (only app + dependencies)
OS)
Slower due to OS virtualization
Performance Faster and more efficient
overhead
Isolation Stronger isolation (full OS per VM) Weaker isolation (shared kernel)
Boot Time Slower (needs to boot full OS) Faster (just start the container)
Running multiple OSes, full OS
Use Cases Microservices, CI/CD, app packaging
isolation
Less portable (dependent on Highly portable (Docker supports various
Portability
hypervisor) platforms)
Size Larger (includes full OS) Smaller (app + dependencies only)
Important Terminologies in Docker
1. Docker Image
It is a file, comprised of multiple layers, used to execute code in a Docker container. They are
a set of instructions used to create docker containers.
2. Docker Container
1
It is a runtime instance of an image. Allows developers to package applications with all parts
needed such as libraries and other dependencies.
3. Docker file
It is a text document that contains necessary commands which on execution helps assemble a
Docker Image.Docker image is created using a Docker file.
4. Docker Engine
The software that hosts the containers is named Docker Engine. Docker Engine is a client- server
based application The docker engine has 3 main components:
Server: It is responsible for creating and managing Docker images, containers, networks, and
volumes on the Docker. It is referred to as a daemon process.
REST API: It specifies how the applications can interact with the Server and instructs it what to
do.
Client: The Client is a docker command-line interface (CLI), that allows us to interact with
Docker using the docker commands.
5. Docker Hub
Docker Hub is the official online repository where you can find other Docker Images that are
available for use. It makes it easy to find, manage, and share container images with others.
Installing Docker on LINUX:
To install Docker on Kali you need to remember that there is already a package named “docker”,
therefore Docker must be installed under a different name. If you install docker you will not end
1
up with the container version. The version we will be installing is named docker.io. All
commands are the same however, so running docker on the command line will be the appropriate
command:
First Create an EC2 instance and connect it to Amazon Linux terminal.
To get the info about the user type whoami and pwd command.
Type cat /etc/*release to know the details of OS.
5
Type sudo install docker to install the docker.
Docker will start getting installed.
6
7
Check the docker version and start the docker for working on it.
Make a separate user for docker using sudo usermod -aG docker ec2-user command.
8
Type docker info to get information about the docker.
9
Information about the docker.
Create an index.html File mkdir my-docker-
app && cd my-docker-app
Create an index.html file inside the directory and Add some HTML content to the file:
Create a Dockerfile
Start the Docker Service
Build the Docker Image
Verify that the image was created:
Run the Docker Container
Access the Application run index.html
Conclusion: We studied and Implemented Containerization using Docker.