CONTAINERIZATION
CONTAINERIZATION
CONTAINERIZATION
4. Vagrant: Vagrant offers the highest levels of isolation on the running physical
machine.
What is Docker?
Available since 2013, docker is an open platform, or engine for developing, shipping,
and running applications as containers.
Docker became popular with developers because of its
simple architecture,
massive scalability,
and portability on multiple platforms, environments, and locations.
Docker is written in the Go programming language
Docker uses Linux kernel features to deliver its functionality.
Docker also uses namespaces to provide an isolated workspace called the container.
Docker creates a set of namespaces for every container and each aspect runs in a
separate namespace with access limited to that namespace.
Docker (Contd…)
Docker isolates applications from infrastructure, including the hardware, the
operating system, and the container runtime.
Docker Container Creation Process
The steps to create and run containers are:
1. Create a Dockerfile.
2. Use the Dockerfile to create a container image.
3. Use the container image to create a running container.
Docker Objects
Docker File
A Dockerfile is a text file that contains instructions needed to create an image.
We can create a Dockerfile using any editor from the console or terminal.
Some of the essential instructions that Docker provides:
1. A Dockerfile must always begin with a FROM instruction that defines a base
image. Often the base image is from a public repository, like an operating system or a
specific language like Go or Node.js.
2. The RUN instruction executes commands.
3. The CMD instruction defines a default command for execution. A Dockerfile should
have only one CMD instruction. If the Dockerfile has several CMD instructions, only
the last CMD instruction will take effect.
Docker File Example – Print Hello
message in container
A simple Node.js application that we will FROM node:9.4.0-alpine
run in a container. The app will print a hello COPY app.js .
message along with the hostname. The
following files are needed to run the app in a COPY package.json .
container: RUN npm install &&\
1. app.js is the main application, which apk update &&\
simply replies with a hello world
apk upgrade
message.
EXPOSE 8080
2. package.json defines the dependencies of
the application. CMD node app.js
3. Dockerfile defines the instructions
Docker uses to build the image.
Docker File Example – Print Hello
message in container (Contd….)
The FROM instruction initializes a new build stage and specifies the base image that
subsequent instructions will build upon.
The EXPOSE instruction exposes a particular port with a specified protocol inside a
Docker Container.
The CMD instruction provides a default for executing a container, or in other words, an
executable that should run in your container.
Docker Images
A Docker Image is a read-only template with
instructions for creating a Docker container.
The Dockerfile provides instructions to build the
image.
Each Docker instruction creates a new layer in the
image.
When we change the Dockerfile and rebuild the
image, the Docker engine only rebuilds the
changed layers. When we instantiate this image, we
Images can share these layers, which saves a lot get a running container.
of disk space as well as network bandwidth when At this point, a writeable container
sending and receiving images. layer is placed on top of the read-only
layers.
Naming Docker Images
An image name has a unique format that
consists of three parts:
the hostname,
the repository,
and the tag.
The hostname identifies the image
registry.
A repository is a group of related container
images.
The tag provides information about a
specific version or variant of an image.
Docker Images Creation
Docker images are created from
DockerFile using docker build command
(as shown in Figure).
The created images can be pushed in a
configured registry using docker push
command (Example: docker push my-
app:v1)
The pushed images can be retrieved from
a configured registry using docker pull
command (Example: docker pull my-
app:v1).
docker images command lists all
images, repositories, tags, and sizes.
Docker Container
A Docker container
is a runnable instance of an image.
We can use the Docker API or CLI to create, start, stop, or delete an image.
Docker keeps containers well isolated from each other and their host machine.
Docker Container vs. Docker Images
Docker Networks, Storage & Plugins
Docker Hub
Docker Hub is the public repository of Docker images that calls itself the “world’s
largest library and community for container images.”
It holds over 100,000 container images sourced from commercial software
vendors, open-source projects, and individual developers.
It includes images that have been produced by Docker, Inc., certified images belonging
to the Docker Trusted Registry, and many thousands of other images.
Docker Containers vs. Virtual Machines (VMs)
Containers and virtual machines have similar resource isolation and allocation benefits, but
function differently because containers virtualize the operating system instead of hardware.
Containers are more portable and efficient.
Docker Containers vs. Virtual Machines (VMs)
Containers are an abstraction at the app
layer that packages code and
dependencies together.
Multiple containers can run on the same
machine and share the OS kernel with
other containers, each running as
isolated processes in user space.
Containers take up less space than VMs
(container images are typically tens of
MBs in size), can handle more
applications and require fewer VMs and
Operating systems.
Docker Containers vs. Virtual Machines (VMs)
• Virtual machines (VMs) are an
abstraction of physical hardware
turning one server into many servers.
• The hypervisor allows multiple VMs to
run on a single machine.
• Each VM includes a full copy of an
operating system, the application,
necessary binaries and libraries -
taking up tens of GBs.
• VMs can also be slow to boot.
Docker Architecture