Containers Containerization a Beginners Guide
Containers Containerization a Beginners Guide
Building containers is necessary if you wish to start using Kubernetes (K8s) or similar options. The
only way to use Kubernetes, which handles the orchestration of containers on servers, is by putting
code into a container.
Fortunately, there’s a lot of help built around packaging code into a container—it is just that
essential. So, exactly what is a container? Let’s find out. In this article, I’ll be introducing
containerization, including:
What’s a container?
Containers are ways to package code and allow it to run on any machine.
Code can be in different languages, rely on other software, install packages from an internet repo,
and require specific system requirements (like memory size) in order to run properly. In
containerization, containers hold all of the figurative nuts and bolts needed to run a program. The
container commands its own runtime environment to include things that allow a program to be
executable, like:
Files
Libraries
Environment variables
This is different from traditional approaches to virtualization, where each application requires an
operating system or an entire virtual machine (VM) to run on the server. Containers are versatile
because they can function on:
Bare-metal servers
Cloud servers
A single virtual machine on a server.
So, instead of cooking in another person’s kitchen, containers allow coders to create their own
kitchens on servers wherever they go. Servers are just personal computers without all the bells and
whistles of a sleek design and a fancy OS to make the server user-friendly. In terms of product
performance, containerization ensures:
Reliability
Consistency
Be more precise
Use remote computers
Instruct exactly what kind of system their software needs to run on
In fact, with containerization, the developers can build it themselves to ensure the software runs and
will not fail.
In containerization, there are two spec files that define what software is required on a machine and
what hardware is required to run the machine. They are the:
1. Dockerfile which controls the runtime environment and the installation of necessary packages
to sufficiently run.
2. Yaml file which controls the hardware and the network security requirements
Apart from understanding the framework, you also need to understand the outcomes. After a
container is created, it forms an image. An image results from the complete set of runtime
components in a single container. Once the code has been containerized, and the image is created,
it can then be deployed on a chosen host. These can be:
On the other hand, containers allow multiple applications to run on a single VM. This limits the
number of software licenses an enterprise company must invest in to develop in a container
environment. They do this by sharing OS kernels, instead of requiring their own. For this reason,
developing in a container is a more resourceful approach, both financially and computation, to
enterprise software development.
(Understand the differences between containers and VMs.)
Enterprise benefits of containerization
Containers are the answer to a lot of problems when teams are developing code:
Containers package code to be shipped by any carrier. It doesn’t matter who is handling it, giving the
customer more power to pick from different providers.
Version control
To remain competitive, container platforms must ensure version control.
Docker set the bar high by offering simplified version control that makes it easy to roll back to a
previous image if your environment breaks. Competitors have followed suit, making this method of
virtualization good for developers who need version control available at their fingertips.
Isolation
A key component of virtualization is isolation, the act of segregating resources for each application.
Container engines perform better than virtual machines when it comes to isolation. But the choice to
use one over the other needs consideration, and depends on the use case.
In general, compared to VMs, containers have:
Security
When Docker debuted, security was thin. Over time, though, Docker has fixed many of the main
issues, like running every container from the Root folder.
Providers of containerization offer different ways to ensure security, but one thing is consistent
across the board. If one of your containers gets hacked, applications running on other containers are
not susceptible.
Still, individual containers are susceptible to attacks, but there exist ways to secure them, through
best practices and third-party monitoring services.
(Follow these security best practices for Docker.)
Versatile & resource-friendly
Most developers like containers because they are a versatile, resource-friendly approach to
software development. Companies can ensure all of their development and deployment needs are
met while conserving server space, whether it’s physical, virtual, or cloud.
Compared to VMs, containers:
Portability
Because container applications can run on cloud servers, they are generally more accessible than
other applications. Programming in containers offers a portable software development approach.
Reproducibility
DevOps loves containerization, especially because it offers the benefit of reproducibility. Each
container’s components remain static and unchanging from code to deployment. They create one
single image that can be reproduced in other containers over and over again.
Businesses continue to adopt cloud technology widely, allowing you to run operations from
the palm of your hands.
The continued growth in adoption of as-a-service providers that package cloud services to
simplify business operations and reduce cost.
While more businesses navigate the tricky waters of making sure their cloud resources are
customized, integrated, automated and functioning as they should, the need for qualified DevOps
professionals has skyrocketed. With more DevOps professionals usually comes a culture shift, one
where two things happen:
Finally, remote teams and employees increase the demand for portability. They work from remote
locations with internet access, often spanning time zones and set working hours, so their
contributions can come in at any time).
Containerization offers exactly what they are looking for—a package for software that ship together.
Contributions can be made any time. Containers offer consistent performance across time zones
and devices.
(Learn more about managing code and containers).
Container systems
A number of services help orchestrate containers, on the cloud in Kubernetes environments or more
traditional single server instances. Here’s a brief look at a few popular options.
Amazon AWS
AWS offers Backend-as-a-Service (BaaS) that includes a Containers-as-a-Service (CaaS) offering to
its customers. It also happens to be a widely used host for those looking to deploy Docker images.
Like Kubernetes, AWS offers the portability of cloud computing.
Cloud Foundry
Cloud Foundry’s Garden is an open source option that offers containerization as part of its Platform-
as-a-Service options (PaaS). Garden is the container engine. Cloud Foundry is the host for
developing, testing, and deploying portable applications on a cloud server.
Requirements file
Here are commands for how to generate a list of all the installed packages on a device. Presumably,
the code has been written in an environment, and compiles fine.
1. Get list of all the installed packages your software depends on—its dependencies.
2. Copy this file to another machine.
3. Install the packages on the machine so it has everything it needs to run.
Below are commands to both get the list of packages and to install the list on another machine.
When a container gets launched on a server, it will need to run these commands to install the
software on the server it just landed on.
These are examples for Ruby and Python. These steps can be found and repeated for any computer
language.
For Python
Get all python packages in your environment:
pip freeze > requirements.txt
For Ruby
Put lists of gems in a file:
xargs gem unpack < $LISTNAME
The Dockerfile is a set of instructions to tell the container what to do when it gets built, which
happens right before it is deployed.
The Dockerfile uses a combination of FROM, RUN, WORKDIR, COPY, RUN, CMD commands with
normal command line inputs afterwards. The following is a simple Dockerfile that:
‘’’
FROM node:12-alpine
RUN apk add --no-cache python g++ make
WORKDIR /app
COPY . .
RUN pip3 install -r requirements.txt
CMD
‘’’
YAML file
The YAML file is a configuration file that tells the Kubernetes servers exactly what the container’s
requirements are to run. If you’ve worked with K8s, you’ll already be familiar with YAML.
The YAML file specifies whether the container needs:
256 MB or 8 GB of memory
An attached volume for data
How many processes it can run
The security measurements
And, really, so much more
Short for either or ‘yet another markup language’ or ‘YAML ain’t markup language’, YAML is a
serialization language that is highly readable. It’s a bit like JSON, to just store data. While it can be
used for many things, it is commonly used for configuration files, such as the config file when
containerizing code.
Nick Chase with Marantis breaks down the YAML further. Here, I have only copied what a YAML
ends up looking like.
‘’’
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: rss-site
labels:
app: web
spec:
replicas: 2
selector:
matchLabels:
app: web
template:
metadata:
labels:
app: web
spec:
containers:
- name: front-end
image: nginx
ports:
- containerPort: 80
- name: rss-reader
image: nickchase/rss-php-nginx:v1
ports:
- containerPort: 88
‘’’
1. Evaluate business needs. Practice running containers on a small scale and see how it fits into
the business model and culture.
2. Pilot containers with your DevOps team.
3. Move into the Production phase and deploy containers into your infrastructure.
Kubernetes orchestrates the deployment of containers on servers—though there are other options,
too. If there are no containers, there is nothing to deploy.
The reason cloud services companies exist is simply because managing servers is costly from a
management perspective and costly as an equipment perspective. While they handle most of the
cloud problems, it is still up to you to make your containers and deploy them onto their service.
Related reading
BMC DevOps Blog
How To Run MongoDB as a Docker Container
The State of Containers Today: A Report Summary
What Is a Citizen Developer?
How To Introduce Docker Containers in The Enterprise, part of our Docker Guide
Containers Aren’t Always the Solution