What is a container ?
A container is a standard unit of software that packages up code and all
its dependencies so the application runs quickly and reliably from one
computing environment to another. A Docker container image is a
lightweight, standalone, executable package of software that includes
everything needed to run an application: code, runtime, system tools,
system libraries and settings.
A container is a bundle of Application, Application libraries required to run
your application and the minimum system dependencies.
Containers vs Virtual Machine
Containers and virtual machines are both technologies used to isolate
applications and their dependencies, but they have some key differences:
1. Resource Utilization: Containers share the host operating system kernel,
making them lighter and faster than VMs. VMs have a full-fledged OS and
hypervisor, making them more resource-intensive.
2. Portability: Containers are designed to be portable and can run on any
system with a compatible host operating system. VMs are less portable as
they need a compatible hypervisor to run.
3. Security: VMs provide a higher level of security as each VM has its own
operating system and can be isolated from the host and other VMs.
Containers provide less isolation, as they share the host operating system.
4. Management: Managing containers is typically easier than managing VMs,
as containers are designed to be lightweight and fast-moving.
Containers are lightweight because they use a technology called
containerization, which allows them to share the host operating system's
kernel and libraries, while still providing isolation for the application and
its dependencies. This results in a smaller footprint compared to
traditional virtual machines, as the containers do not need to include a full
operating system. Additionally, Docker containers are designed to be
minimal, only including what is necessary for the application to run,
further reducing their size.
Let's try to understand this with an example:
Below is the screenshot of official ubuntu base image which you can use
for your container. It's just ~ 22 MB, isn't it very small ? on a contrary if
you look at official ubuntu VM image it will be close to ~ 2.3 GB. So the
container base image is almost 100 times less than VM image.
To provide a better picture of files and folders that containers base
images have and files and folders that containers use from host operating
system (not 100 percent accurate -> varies from base image to base
image). Refer below.