Sie sind auf Seite 1von 8

FEATURE

Empower Docker to Make


Sufficient Infrastructure
Available Effectively as well
as Efficiently for Learning
and Development
By Dr B Thangaraju and Rajesh Srivastava

1. Introduction Operating System (OS) can be either Linux or Windows or


even other flavors of Linux (RHEL, Fedora, Ubuntu, Cen-
Thanks to open source era, which ensured technology tOS etc.). Thanks to concepts of Virtualization such as VM-
changes to take place rapidly in Information Technology WARE or Virtual Box or Kernel Virtual Machine (KVM)
(IT) industries. In order to embrace these new technologies, due to which we could create virtual machines with the re-
companies rollout numerous initiatives. Every initiative re- quired operating system irrespective of host operating sys-
quires investments from time and money both standpoints tem. However, installing VM is not only a very time con-
for skill building as well as competency development. suming exercise but number of VM creation is limited also
because each VM consumes considerable amount of system
To build competencies and skills for various levels, techni- resources.
cal trainings play a vital role. Usually the mode of train-
ings start from in-house class room based Instructor Led Today, online trainings replace the class room based train-
Trainings (ILT), computer based trainings, online trainings, ings since it gives more convenience, flexibility and domi-
on-job trainings with simulated project environment that is nance. However, it is always a face many issues to conduct
achieved through developing of virtual projects. as well as monitor hands-on for the participants over online
trainings. Though commercial cloud Infra is available today
To provide infrastructure for different types of training to do to provide lab environment for online trainings on the fly but
hands-on is always a challenge. Each training needs specific it comes with an additional cost. Apart from cost, flexibility
lab setup including different installation of operating sys- becomes a bottleneck as compared to tailor made develop-
tem along with necessary other package or application. The ment environment in our local system.

54 DeveloperIQ | March 2016


FEATURE
This article describes step by step implementation proce-
dure to create Linux containers for system administration
trainings. The learning mode may be either Instructor lead
class room training or online WebEx trainings. It also dem-
onstrates to check participants hands-on activity through
online.

2. Evolution of Infrastructure Path Virtual Machines (VMs) had been solving a great problem
of costly machines through providing one server and con-
Let us dwell a little on evolution that has taken place in In- necting through VM sessions. Virtual Machine emulates
frastructure space gradually. dedicated hardware. Apart from big cost saving, virtualiza-
tion has several other important advantages:
Days are gone when one dedicated full loaded machine is
needed to perform feats in Linux world. It has been always a) High Scalability through increased RAM, Disk Space
a topic of research to provide hands-on experience to the all or CPU
participants with appropriate infrastructure. Evolution has b) Zero waiting period for new hardware
always been a key. In the world of expensive infrastructures, c) Simple layout from cable and wiring standpoints
evolution is to provide same infrastructure and experience d) Real Estate saving
with less investment.

It has not been possible to provide a dedicated and fully 2.2 Evolution Tranche 2
loaded machine for getting hands on experience to the par-
ticipants in majority of the trainings, especially when there However, the biggest challenge with Hardware Virtualiza-
are various technologies are involved as depicted in Figure tion was that the system processes in VM used 90% of re-
1. For every technology, a different set of infrastructural re- sources. Hence, what is left for applications to use?
quirement is needed.
Yes, you are right. Just 10% resources are used by
application(s).

As we all know, necessity is the mother of invention. To


overcome this challenge, concept of Linux container came
into picture. Container focuses on Software level Virtualiza-
tion. While keeping the advantages of hardware virtualiza-
tion intact, the virtualization was done at Operating System
Therefore, it becomes significant to optimize infrastructure level. Figure 3 depicts many users with one system through
to cater to various technologies and make it available to all Docker container.
participants to practice through hands-on exercises. The
evolution can be described in two tranches as follows:

2.1 Evolution Tranche 1


Keeping this into mind, hardware virtualization came into
existence that helped in big way as depicted in Figure 2.

DeveloperIQ | March 2016 55


FEATURE
Software level virtualization has helped every participant to Traditionally Docker is used mainly for service oriented
have a clone of real system from all technical standpoints tasks such as executing a service with a dedicated contain-
to perform hands-on exercises. Also faculty or admin can er. For example, to run a Web Server, container based web
monitor each and every participant from remote. server replaces the full fledge Linux server efficiently. Effi-
cient in the sense that in general when we run a VM or Phys-
2.3 Evolution Journey ical system, more than 200 processes run once the system
is up for use. These processes are mostly system processes,
Journey of hardware and software level virtualizations to needed to present GUI working environment for a user. But
maximize utilization is depicted Figure 4 as its transformed to run a single service, this setup is redundant. Docker runs
over a period of time. in Linux host as a process i.e. inside the container only one
process runs. That means, if we launch a container in an in-
teractive mode, only shell will be running that allows us to
run a container with less consumption of system resources
compared to VM. Consequently we can run large number of
Docker containers in a server.

Figure 5 and Figure 6 show the screen shot of top command


output of virtual machine and Docker container respectively.

3. How does it work - Detail

3.1 Docker An Open Source Tool

With the arrival of Linux containers, it is made possible to Figure 5. Top command screen shot in Linux Server
spin off an isolated Linux system from a Linux host. Real
life hands-on based Linux trainings will surely help in solv-
ing real-world practical issues and practice to work in a
software project or product in open source arena. However,
creating individual system to do practical exercises is a her-
culean task that requires good amount of time, effort and
money. It requires many systems either virtual or physical
machines. Figure 6. Top command output in Docker container

Thanks to Docker to solve this problem in a perfect way! From the figures, you can make out, only 2 processes are
Docker is a Linux based container management tool and running in the container bash and top command, which
each container is isolated from others in a server. We can we execute in the bash shell. Whereas, the Figure 5, there
create required number of user accounts and allocate con- are 211 processes are running even though we havent run
tainer for each user dynamically. Each user will have expe- any applications.
rience as if they have their own individual system with root
privileges for their hands-on exercises. The advantage of using containers in simple term is agility.

56 DeveloperIQ | March 2016


FEATURE
Containers are lightweight, consume less of resources and cgroup from Control Groups Series by Neil Brown [1] and
can be created or deleted instantly with a great performance. namespace at Namespaces by Michael Kerrisk [2].
In addition to this, a system administrator can monitor all
running containers resource utilization, their processes in As illustrated earlier, virtual machines are hardware level
a specific container that enables them to debug running ap- virtualization. One can envisage, that VM runs virtually on
plication, when needed. hardware. Hypervisor is used in between VM and hardware
to provide virtualization capabilities. Though hypervisor
So while conducting technical training to provide hands-on plays a role of an interface between host and VM but at a
environments to good number of participants with Docker high operating cost. Containers are operating system level
container, faculty can monitor all containers effectively. virtualization, to be more specific it is kernel level virtual-
This helps faculty to take control of user systems and show ization that is made possible without Hypervisor.
a demo or debug the faulty program.
Container runs as a user process inside the server helps mak-
Log file captures containers standard input, output and ing every operation possible as it is done by a user process
errors. The log file remains in the server till we delete the such as creation, deletion, monitor, performance tuning etc.
container. Container log file is captured in the server that en- At the same time, it is isolated from other system processes
ables faculty to view participants working in offline mode in the server. Therefore, each container works as good as
post training completion. stand-alone system. Container can have its own process ids,
mounted file systems, system resources, network and logs.
3.2. Container Internals The execution of a container is achieved without adding any
overhead to the hypervisor, launching a container is miracu-
Let us discuss in brief about the internals of container. A lously fast.
set of processes are called as a group. For each group, we
can set process attributes and proportionate share of sys- 3.3. Lab Infra Setup for Technical Training
tem resources like CPU, Memory, Disk space and Network
Interface. The cgroup feature takes care of allocation and If one wants to communicate between two different systems
controlling of system resources for a group. The cgroup has over separate networks, one needs to use socket program-
resource controller that monitors as well as keeps account- ming. Similarly communication between the host and con-
ing for the resource usage. The cgroup is used by many of tainer is done by Docker as it is a client-server application.
its subsystems such as debug, devices, freezer, perf-event, The Docker daemon or client sends command to the server
cpu, cpuset, cpuacct, memory, hugetlb, blkio, net-cls and and the server performs the task and returns as per clients
systemd. These subsystems can be viewed in /sys/fs/cgroup command.
directory. The process id inside the group is global therefore
it is NOT isolated from the host. However, our requirement Docker package contains command line client binary and
is to isolate each group. RESTful API. The system requirement as well as step by
step procedure for docker installation in various Linux dis-
Docker uses native Linux features mainly namespace and tributions and Windows can be found in detail at [3].
cgroup. Namespace feature helps the group to isolate its pro-
cess ids from the host system. The isolation features are im- The base Docker image can be downloaded from the docker
plemented in mounted file system, UTS, IPC, PID, Network registry. The standard Linux flavors docker images is listed
and User. This way, each group is create as an isolated envi- in Figure 7.
ronment for a user with the help of cgroup and namespace.
The interested readers can get more detail information about

DeveloperIQ | March 2016 57


FEATURE
In a typical training session, the system administrator will
create user accounts and share the login credentials to the
user. We keep the entire users login id in a file called as user.
txt, which is shown in Figure 9. Then we wrote a shell script
Figure 7. List of Docker base image to create container for each user and set the container name
is same as the users login id. This will help to identify the
First determine, the desired state of your system then identi-
owner of the running container. Figure 10 shows the script
fy what are the necessary packages are needed to do hands-
to create containers for each user.
on for a specific trainings. The different kinds of trainings
would be: UNIX basics and shell scripting, programming
language training courses like C, C++, JAVA, Python and
Ruby, UNIX Internals, Linux Systems Programming, Li-
nux System Administrations etc., Second, start and run the
container from the given list of Docker images based on
our choice, install the necessary packages, applications, list
of lab exercises, demo programs, manual pages, debugging
Figure 9. File to store user logins
tools, monitoring tools in the running container. Once you
verify all your lab exercises are working well in the contain-
er then commit the changes in the container and create your
own Docker image with appropriate name for example we
have run container using ubuntu base image and installed
necessary sysadmin packages and commit the changes in
the running container and created a new base image as sys-
admin as shown in Figure 8.
Figure 10. Script to create user container

Shell script can be executed by $sh <script name>, with x


option we can debug the script. Here, we used the x option
to understand how the containers are created by the script.
Figure 11 demonstrates the Docker creation steps with the
Figure 8. command to create sysadmin Docker image
user login ids.
Using these Docker images, one can launch container. The
pre-built images can be stored locally or can be download-
ed from Docker registry [4]. The Docker images contain
source code of the containers. Images are portable as well
as can be shared, stored and modified. One can build Docker
images as per specified requirement with built-in installed
packages and services.

The difference between container and image can be under-


stood as below:

a) Container is running an instance of a Docker.

b) Images are bundle of required software Figure 11. Step by Step execution of script

58 DeveloperIQ | March 2016


FEATURE
We can list all the created containers, which is as shown in of the owners for the running container is user6. if faculty
Figure 12. wants to see activities of user6, he or she can get static in-
formation in the corresponding container logs. Figure 14
shows the user6 logs.

Figure 12. List of created user containers


Figure 14. User6 containers log file
To monitor the computing resources utilization of the run-
ning containers, we can execute the command as: $docker Figure 15 shows how to monitor user6 container in real
stats <container name(s)>. Figure 13 shows the resource uti- time.
lization output for the running users containers.

Figure 13. Monitor computing resource usage of running Figure 15. Monitor user6 containers activity in real time
containers through log file

3.4. Monitor Progress during Training It is always a requirement to get control of a user system to
debug their program or show a demo as needed. This feature
Any user who logs in into the server, will start their own is easily incorporated through Docker. We need to just at-
container by executing the command: tach to a specific container in our terminal. With an admin
privileges, a faculty can take control of participants con-
$docker start <login id> tainer to monitor or help participant as required.

Then attach the container into their shell to get container Figure 16 illustrated on a faculty taking system control of
prompt: user6 through Docker attach command. Any action done by
faculty can be seen on both the systems of facultys as well
$docker attach <login id> as participant (Top one is facultys systems window and the
user6s container is shown at the bottom).
After execution of the above command, the user will get the
container shell prompt to work on. This container works for
that the user as a system with supervisor mode.

As mentioned earlier as well for a faculty, it is always a chal-


lenge to monitor and debug user system remotely. Through
Docker, this challenge is overcome with ease. For example,
there are many containers are running in our system. One

DeveloperIQ | March 2016 59


FEATURE
5. References
1. Control Groups Series by Neil Brown -- https://lwn.net/
Articles/604609/
2. Namespaces by Michael Kerrisk -- https://lwn.net/
Articles/531114/
3. The Docker Book by James Turnbull, pp. 18-47, August
16, 2015, v1.8.0, --http://www.dockerbook.com/
4. Docker Registry -- https://hub.docker.com/

6. Authors Detail

First Author: Dr B. Thangaraju re-


ceived his Ph.D. in Physics and
Figure 16. Faculty taking system control of user6 worked as a research associate in the
Indian Institute of Science (IISc.),
Once the training is over, faculty can delete all the created Bangalore before joining in Wipro
containers by executing the below command: Technologies. His core expertise
lies in Linux kernel with knowledge
$docker rm $(ps a q) of embedded, real-time Linux, Open
Source Software (OSS) and Dev-Ops. He has published
It takes 3 minutes to delete 25 user accounts and contain- more than 55 papers on OSS in renowned international and
ers. national journals. Also he has presented 32 technical papers
in national and international conferences. You can reach him
at: balat.raju@wipro.com.

To summarize, the evolution has taken place in two Second Author: Rajesh Srivas-
tranches. In first one, hardware virtualization was done tava completed his engineer-
through Virtual machines that provided certain advantag- ing in computers and currently
es. To overcome challenges or limitations associated with playing a unique role i.e. Social
hardware virtualization, software virtualization was done Officer for Talent Transforma-
through Docker to fetch maximum benefits of the virtual- tion of Wipro Technologies,
izations. Bangalore. He is an alumnus
from Madan Mohan Malaviya
University of Technology, Gor-
We discussed the steps to customize Docker image based
akhpur and Stanford University California, USA. He has
on your requirements, the creation of container from the
been working with IT industry for almost two decades. He
list of users, monitor the computing resource utilization of
possess versatile experience in technology and management
running containers and check the user activities through
areas. You can reach Rajesh at rajesh.srivastava@wipro.
log files in both online as well as offline. com

60 DeveloperIQ | March 2016

Das könnte Ihnen auch gefallen