0% found this document useful (0 votes)
16 views63 pages

Devops Q&A

DevOps is a methodology that combines software development and operations to enhance collaboration and efficiency throughout the application lifecycle. It offers advantages such as faster deployment and improved customer satisfaction, but also has challenges like a shortage of skilled professionals and high costs. The document outlines key DevOps tools, principles, lifecycle phases, and the importance of software configuration management in maintaining software quality.

Uploaded by

Sanket More
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views63 pages

Devops Q&A

DevOps is a methodology that combines software development and operations to enhance collaboration and efficiency throughout the application lifecycle. It offers advantages such as faster deployment and improved customer satisfaction, but also has challenges like a shortage of skilled professionals and high costs. The document outlines key DevOps tools, principles, lifecycle phases, and the importance of software configuration management in maintaining software quality.

Uploaded by

Sanket More
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 63

ALIK SARKAR

018

1. What is meant by DevOps?


Ans:
The DevOps is a combination of two words, one is software Development, and second is Operations. This allows a single team to
handle the entire application lifecycle, from development to testing, deployment, and operations. DevOps helps you to reduce the
disconnection between software developers, quality assurance (QA) engineers, and system administrators.

DevOps is nothing but a practice or methodology of making "Developers" and "Operations" folks work together. DevOps
represents a change in the IT culture with a complete focus on rapid IT service delivery through the adoption of agile practices in
the context of a system-oriented approach. DevOps can also be defined as a sequence of development and IT operations
with better communication and collaboration.

2. List the advantages and disadvantages of DevOps


Advantages
o DevOps is an excellent approach for quick development and deployment of applications.
o It responds faster to the market changes to improve business growth.
o DevOps escalate business profit by decreasing software delivery time and transportation costs.
o DevOps clears the descriptive process, which gives clarity on product development and delivery.
o It improves customer experience and satisfaction.
o DevOps simplifies collaboration and places all tools in the cloud for customers to access.
o DevOps means collective responsibility, which leads to better team engagement and productivity.
Disadvantages
o DevOps professional or expert's developers are less available.
o Developing with DevOps is so expensive.
o Adopting new DevOps technology into the industries is hard to manage in short time.
o Lack of DevOps knowledge can be a problem in the continuous integration of automation
projects.

3. Name some of the most important DevOps tools (category wise).


1) Puppet
Puppet is the most widely used DevOps tool. It allows the delivery and release of the technology changes
quickly and frequently. It has features of versioning, automated testing, and continuous delivery. It
enables to manage entire infrastructure as code without expanding the size of the team.
Features
o Real-time context-aware reporting.
o Model and manage the entire environment.
ALIK SARKAR
018

o Defined and continually enforce infrastructure.


o Desired state conflict detection and remediation.
o It inspects and reports on packages running across the infrastructure.
o It eliminates manual work for the software delivery process.
o It helps the developer to deliver great software quickly.
2) Ansible
Ansible is a leading DevOps tool. Ansible is an open-source IT engine that automates application
deployment, cloud provisioning, intra service orchestration, and other IT tools. It makes it easier for
DevOps teams to scale automation and speed up productivity.
21.5M
299
Triggers in SQL (Hindi)
Ansible is easy to deploy because it does not use any agents or custom security infrastructure on the
client-side, and by pushing modules to the clients. These modules are executed locally on the client-side,
and the output is pushed back to the Ansible server.
Features
o It is easy to use to open source deploy applications.
o It helps in avoiding complexity in the software development process.
o It eliminates repetitive tasks.
o It manages complex deployments and speeds up the development process.
3) Docker
Docker is a high-end DevOps tool that allows building, ship, and run distributed applications on multiple
systems. It also helps to assemble the apps quickly from the components, and it is typically suitable for
container management.
Features
o It configures the system more comfortable and faster.
o It increases productivity.
o It provides containers that are used to run the application in an isolated environment.
o It routes the incoming request for published ports on available nodes to an active container. This
feature enables the connection even if there is no task running on the node.
o It allows saving secrets into the swarm itself.
4) Nagios
ALIK SARKAR
018

Nagios is one of the more useful tools for DevOps. It can determine the errors and rectify them with the
help of network, infrastructure, server, and log monitoring systems.
Features
o It provides complete monitoring of desktop and server operating systems.
o The network analyzer helps to identify bottlenecks and optimize bandwidth utilization.
o It helps to monitor components such as services, application, OS, and network protocol.
o It also provides to complete monitoring of Java Management Extensions.
5) CHEF
A chef is a useful tool for achieving scale, speed, and consistency. The chef is a cloud-based system and
open source technology. This technology uses Ruby encoding to develop essential building blocks such as
recipes and cookbooks. The chef is used in infrastructure automation and helps in reducing manual and
repetitive tasks for infrastructure management.
Chef has got its convention for different building blocks, which are required to manage and automate
infrastructure.
Features
o It maintains high availability.
o It can manage multiple cloud environments.
o It uses popular Ruby language to create a domain-specific language.
o The chef does not make any assumptions about the current status of the node. It uses its
mechanism to get the current state of the machine.
6) Jenkins
Jenkins is a DevOps tool for monitoring the execution of repeated tasks. Jenkins is a software that allows
continuous integration. Jenkins will be installed on a server where the central build will take place. It
helps to integrate project changes more efficiently by finding the issues quickly.
Features
o Jenkins increases the scale of automation.
o It can easily set up and configure via a web interface.
o It can distribute the tasks across multiple machines, thereby increasing concurrency.
o It supports continuous integration and continuous delivery.
o It offers 400 plugins to support the building and testing any project virtually.
o It requires little maintenance and has a built-in GUI tool for easy updates.
7) Git
ALIK SARKAR
018

Git is an open-source distributed version control system that is freely available for everyone. It is
designed to handle minor to major projects with speed and efficiency. It is developed to co-ordinate the
work among programmers. The version control allows you to track and work together with your team
members at the same workspace. It is used as a critical distributed version-control for the DevOps tool.
Features
o It is a free open source tool.
o It allows distributed development.
o It supports the pull request.
o It enables a faster release cycle.
o Git is very scalable.
o It is very secure and completes the tasks very fast.
8) SALTSTACK
Stackify is a lightweight DevOps tool. It shows real-time error queries, logs, and more directly into the
workstation. SALTSTACK is an ideal solution for intelligent orchestration for the software-defined data
center.
Features
o It eliminates messy configuration or data changes.
o It can trace detail of all the types of the web request.
o It allows us to find and fix the bugs before production.
o It provides secure access and configures image caches.
o It secures multi-tenancy with granular role-based access control.
o Flexible image management with a private registry to store and manage images.
9) Splunk
Splunk is a tool to make machine data usable, accessible, and valuable to everyone. It delivers operational
intelligence to DevOps teams. It helps companies to be more secure, productive, and competitive.
Features
o It has the next-generation monitoring and analytics solution.
o It delivers a single, unified view of different IT services.
o Extend the Splunk platform with purpose-built solutions for security.
o Data drive analytics with actionable insight.
10) Selenium
ALIK SARKAR
018

Selenium is a portable software testing framework for web applications. It provides an easy interface for
developing automated tests.
Features
o It is a free open source tool.
o It supports multiplatform for testing, such as Android and ios.
o It is easy to build a keyword-driven framework for a WebDriver.
o It creates robust browser-based regression automation suites and tests.

4. Outline the fundamental principles of DevOps.


5. Why DevOps is important? / Benefits of using DevOps.
DevOps is important because it's a software development and operations approach that enables
faster development of new products and easier maintenance of existing deployments.
benefits of DevOps
DevOps enables that by helping your teams focus on the customer experience, uniting teams for faster
product shipments, simplifying the goals of each release, introducing automation (which reduces errors
and frees developer time for other projects) and creating a feedback loop that benefits the entire company.

6. Explain DevOps Lifecycle with a diagram.


DevOps Lifecycle

DevOps defines an agile relationship between operations and Development. It is a process that is practiced by the
development team and operational engineers together from beginning to the final stage of the product.
ALIK SARKAR
018

Learning DevOps is not complete without understanding the DevOps lifecycle phases. The DevOps lifecycle
includes seven phases as given below:

1) Continuous Development

This phase involves the planning and coding of the software. The vision of the project is decided during the planning
phase. And the developers begin developing the code for the application. There are no DevOps tools that are
required for planning, but there are several tools for maintaining the code.

2) Continuous Integration

This stage is the heart of the entire DevOps lifecycle. It is a software development practice in which the developers
require to commit changes to the source code more frequently. This may be on a daily or weekly basis. Then every
commit is built, and this allows early detection of problems if they are present. Building code is not only involved
compilation, but it also includes unit testing, integration testing, code review, and packaging.

OOPs Concepts in Java

The code supporting new functionality is continuously integrated with the existing code. Therefore, there is
continuous development of software. The updated code needs to be integrated continuously and smoothly with the
systems to reflect changes to the end-users.
ALIK SARKAR
018

Jenkins is a popular tool used in this phase. Whenever there is a change in the Git repository, then Jenkins fetches
the updated code and prepares a build of that code, which is an executable file in the form of war or jar. Then this
build is forwarded to the test server or the production server.

3) Continuous Testing

This phase, where the developed software is continuously testing for bugs. For constant testing, automation testing
tools such as TestNG, JUnit, Selenium, etc are used. These tools allow QAs to test multiple code-bases thoroughly
in parallel to ensure that there is no flaw in the functionality. In this phase, Docker Containers can be used for
simulating the test environment.

Selenium does the automation testing, and TestNG generates the reports. This entire testing phase can automate
with the help of a Continuous Integration tool called Jenkins.

Automation testing saves a lot of time and effort for executing the tests instead of doing this manually. Apart from
that, report generation is a big plus. The task of evaluating the test cases that failed in a test suite gets simpler. Also,
we can schedule the execution of the test cases at predefined times. After testing, the code is continuously integrated
with the existing code.

4) Continuous Monitoring
ALIK SARKAR
018
Monitoring is a phase that involves all the operational factors of the entire DevOps process, where important
information about the use of the software is recorded and carefully processed to find out trends and identify problem
areas. Usually, the monitoring is integrated within the operational capabilities of the software application.

It may occur in the form of documentation files or maybe produce large-scale data about the application parameters
when it is in a continuous use position. The system errors such as server not reachable, low memory, etc are resolved
in this phase. It maintains the security and availability of the service.

5) Continuous Feedback

The application development is consistently improved by analyzing the results from the operations of the software.
This is carried out by placing the critical phase of constant feedback between the operations and the development of
the next version of the current software application.

The continuity is the essential factor in the DevOps as it removes the unnecessary steps which are required to take a
software application from development, using it to find out its issues and then producing a better version. It kills the
efficiency that may be possible with the app and reduce the number of interested customers.

6) Continuous Deployment

In this phase, the code is deployed to the production servers. Also, it is essential to ensure that the code is correctly
used on all the servers.

The new code is deployed continuously, and configuration management tools play an essential role in executing
tasks frequently and quickly. Here are some popular tools which are used in this phase, such as Chef, Puppet,
Ansible, and SaltStack.

Containerization tools are also playing an essential role in the deployment phase. Vagrant and Docker are popular
tools that are used for this purpose. These tools help to produce consistency across development, staging, testing,
and production environment. They also help in scaling up and scaling down instances softly.

Containerization tools help to maintain consistency across the environments where the application is tested,
developed, and deployed. There is no chance of errors or failure in the production environment as they package and
replicate the same dependencies and packages used in the testing, development, and staging environment. It makes
the application easy to run on different computers.
ALIK SARKAR
018
7) Continuous Operations

All DevOps operations are based on the continuity with complete automation of the release process and allow the
organization to accelerate the overall time to market continuingly.

It is clear from the discussion that continuity is the critical factor in the DevOps in removing steps that often distract
the development, take it longer to detect issues and produce a better version of the product after several months.
With DevOps, we can make any software product more efficient and increase the overall count of interested
customers in your product.

7. Elaborate the activities in software configuration management


Software Configuration Management
When we develop software, the product (software) undergoes many changes in their maintenance phase;
we need to handle these changes effectively.
Several individuals (programs) works together to achieve these common goals. This individual produces
several work product (SC Items) e.g., Intermediate version of modules or test data used during debugging,
parts of the final product.
The elements that comprise all information produced as a part of the software process are collectively
called a software configuration.
As software development progresses, the number of Software Configuration elements (SCI's) grow
rapidly.
These are handled and controlled by SCM. This is where we require software configuration
management.
A configuration of the product refers not only to the product's constituent but also to a particular version
of the component.
Therefore, SCM is the discipline which
o Identify change
o Monitor and control change
o Ensure the proper implementation of change made to the item.
o Auditing and reporting on the change made.
Configuration Management (CM) is a technic of identifying, organizing, and controlling modification to
software being built by a programming team.
The objective is to maximize productivity by minimizing mistakes (errors).
CM is used to essential due to the inventory management, library management, and updation management
of the items essential for the project.

Importance of SCM
ALIK SARKAR
018

It is practical in controlling and managing the access to various SCIs e.g., by preventing the two members
of a team for checking out the same component for modification at the same time.
It provides the tool to ensure that changes are being properly implemented.
It has the capability of describing and storing the various constituent of software.
SCM is used in keeping a system in a consistent state by automatically producing derived version upon
modification of the same component.

8. Outline the activities involved in software development lifecycle with a


Diagram
SDLC Cycle
SDLC Cycle represents the process of developing software. SDLC framework includes the following
steps:

The stages of SDLC are as follows:


Stage1: Planning and requirement analysis
Requirement Analysis is the most important and necessary stage in SDLC.
The senior members of the team perform it with inputs from all the stakeholders and domain experts or
SMEs in the industry.
Planning for the quality assurance requirements and identifications of the risks associated with the
projects is also done at this stage.
ALIK SARKAR
018

Business analyst and Project organizer set up a meeting with the client to gather all the data like what the
customer wants to build, who will be the end user, what is the objective of the product. Before creating a
product, a core understanding or knowledge of the product is very necessary.
For Example, A client wants to have an application which concerns money transactions. In this method,
the requirement has to be precise like what kind of operations will be done, how it will be done, in which
currency it will be done, etc.
Once the required function is done, an analysis is complete with auditing the feasibility of the growth of a
product. In case of any ambiguity, a signal is set up for further discussion.
Once the requirement is understood, the SRS (Software Requirement Specification) document is created.
The developers should thoroughly follow this document and also should be reviewed by the customer for
future reference.
Stage2: Defining Requirements
Once the requirement analysis is done, the next stage is to certainly represent and document the software
requirements and get them accepted from the project stakeholders.
This is accomplished through "SRS"- Software Requirement Specification document which contains all
the product requirements to be constructed and developed during the project life cycle.
Stage3: Designing the Software
The next phase is about to bring down all the knowledge of requirements, analysis, and design of the
software project. This phase is the product of the last two, like inputs from the customer and requirement
gathering.
Stage4: Developing the project
In this phase of SDLC, the actual development begins, and the programming is built. The implementation
of design begins concerning writing code. Developers have to follow the coding guidelines described by
their management and programming tools like compilers, interpreters, debuggers, etc. are used to develop
and implement the code.
Stage5: Testing
After the code is generated, it is tested against the requirements to make sure that the products are solving
the needs addressed and gathered during the requirements stage.
During this stage, unit testing, integration testing, system testing, acceptance testing are done.
Stage6: Deployment
Once the software is certified, and no bugs or errors are stated, then it is deployed.
Then based on the assessment, the software may be released as it is or with suggested enhancement in the
object segment.
After the software is deployed, then its maintenance begins.
Stage7: Maintenance
ALIK SARKAR
018

Once when the client starts using the developed systems, then the real issues come up and requirements to
be solved from time to time.
This procedure where the care is taken for the developed product is known as maintenance.

9. Explain Agile Methodology.


An agile methodology is an iterative approach to software development. Each iteration of agile methodology takes a
short time interval of 1 to 4 weeks. The agile development process is aligned to deliver the changing business
requirement. It distributes the software with faster and fewer changes.

The single-phase software development takes 6 to 18 months. In single-phase development, all the requirement
gathering and risks management factors are predicted initially.

The agile software development process frequently takes the feedback of workable product. The workable product is
delivered within 1 to 4 weeks of iteration.

Roles in Agile

There are two different roles in a Agile methodology. These are the Scrum Master and Product Owner.
ALIK SARKAR
018
1. Scrum Master

The Scrum Master is a team leader and facility provider who helps the team member to follow agile practices, so
that the team member meets their commitments and customers requirements. The scrum master plays the following
responsibilities:

o They enable the close co-operation between all the roles and functions.

o They remove all the blocks which occur.

o They safeguard the team from any disturbances.

o They work with the organization to track the progress and processes of the company.

o They ensure that Agile Inspect & Adapt processes are leveraged correctly which includes

o Planned meetings

o Daily stand-ups

o Demo

o Review

o Retrospective meetings, and

o Facilitate team meetings and decision-making process.

2. Product Owner

The Product Owner is one who runs the product from a business perspective. The Product Owner plays the
following responsibilities:

o He defines the requirements and prioritizes their values.

o He sets the release date and contents.

o He takes an active role in iteration and releasing planning meetings.

o He ensures that the team is working on the most valued requirement.

o He represents the voice of the customer.

o He accepts the user stories that meet the definition of done and defined acceptance criteria.

Cross-functional team

Every agile team contains self-sufficient team with 5 to 9 team members. The average experience of each member
ranges from 6 to 10 years. The agile team contains 3 to 4 developers, 1 tester, 1 technical lead, 1 scrum master and 1
product owner.

The Scrum master and Product owner are considered as a part of Team Interface, on the other hand remaining
members are the part of Technical Interface.
ALIK SARKAR
018

10.Explain Lean and ITIL means to DevOps.


Lean is defined as a set of management practices to improve efficiency and effectiveness by
eliminating waste. The core principle of lean is to reduce and eliminate non-value adding activities and
waste.
ITIL stands for Information Technology Infrastructure Library. It’s actually used to guide it team to
improve the value of service by focusing on solving the business issues and creating business value. One
of the important parts of ITIL is the configuration management database which provides services, users,
software, hardware, documents, and IT components to the central authority. ITIL has been adopted by
thousands of organizations worldwide like Microsoft, NASA, and HSBC. ITIL’s current version which is
use in the market is ITIL4, it provides a practical and flexible basis to support organizations for a digital
transformation.

11. What are the objectives of DevOps


12. List various DevOps best practices
1. Active Participation of Stakeholders

One of the key practices for DevOps is the active participation of stakeholders. As a fundamental philosophy, the
operation staff, developers, and the support people need to work closely regularly. When the key stakeholders of the
software development process work together, the outcomes are sure to be of the high standard.

2. Automate the Infrastructure

Automating the infrastructure is one of the important DevOps practices in agile. The agile software developers focus
on quality codes and desire to test the codes early and as often as possible. It necessitates the automation of the
infrastructure. With the automated infrastructure, automated scripts can help in enhancing the process throughout the
development cycle, resulting in more robust versions of the software.

Test automation is applicable for middleware configurations, code development, and data and networking changes.
Test automation starts with identifying the test cases and scenarios and selecting the appropriate automation tools.
Then by running the test cases and analyzing the outcomes can help in accomplishing test automation, which one of
the important DevOps best practices. Automated testing enables quicker execution of the software development life
cycle.

3. Integrated Change Management

The IT infrastructure is continuously evolving with the advancements in technology. The continuous evolution
makes integrated change management one of the DevOps best practices 2019. Change management refers to the
process of making changes to the configurations to meet the new requirements and the dynamic circumstances.

Though the change management process might be a little tricky, it helps in providing better support to the overall
organization. As DevOps brings enterprise-level issues that are related to operations, it makes the formulation of the
integrated change management strategy complex. While incorporating the integrated change management strategies,
the development team will have to work together to understand the impact of the technology changes.

4. Integrated Configuration Management

Apart from the integrated change management, integration configuration management is DevOps best practices.
Change management and configuration management are integral to operations. Configuration management includes
monitoring, automation, maintenance, and management of the system-wide configurations across all servers,
networks, applications, and other managed services.
ALIK SARKAR
018
In the DevOps environment, there is a need for the developers to look into the bigger picture. Integrated
configuration management enables them to look at the broader aspect. With the integrated approach, the
development team focuses on the configuration issues of the complete infrastructure of the organization.

It enables the developers to make use of the existing services for software development instead of investing time in
developing new services from scratch. It also enables the operation staff to have a better understanding of the
potential impact of the new releases and assist them in making the right decision regarding the right time for a new
release.

5. Integrated Deployment Planning

Deployment planning is an important element of software development. It is also one of the AWS DevOps best
practices. Deployment planning requires interaction between the operation staff, developers, and support groups.
Deployment planning continues throughout the software development process. While adopting the DevOps strategy,
there is a growing need to follow the cross-team approach. Integrated deployment planning helps meet the quality
requirement of the new software releases.

6. Product Support

A majority of the development teams work on the new releases that already exist in the production. In such an
environment, the team also has an additional responsibility to address the production problems. Product support is
identified as yet another DevOps best practices of recent times. The practice of production support offers the
development team an opportunity to learn and improve the process of designing the software.

7. Continuous Integration

Continuous integration is one of the key practices for DevOps. It basically refers to the building as well as validating
a project regularly. It is a practice that requires the development team to update the changes in code in the repository
regularly. The continuous integration tools help in figuring out the integration challenges and finding out optimum
solutions.

The practice of continuous integration enables developers to conduct integrations frequently. Continuous integration
ensures the development of high-quality software by providing regular and immediate feedback. It enables better
collaboration among the development team and helps in building quality software products.

8. Continuous Deployment

Continuous deployment is one of the Azure DevOps best practices. It is simply an extension of the continuous
integration practice. The deployment process encompasses many sub-processes, including creation, versioning,
testing, deployment, and more. Through continuous deployment, the code is deployed automatically in the
production environment.

With the help of the various tools available, the developers perform continuous deployment right from the staging to
the production. The continuous deployment approach helps the development team in reducing the time between the
identification of the new features and its deployment in production. It helps in building a more responsive
organization. Even though continuous deployment creates a chance of more operational risk, it is considered as one
of the DevOps best practices.

9. Continuous Delivery

Continuous delivery is yet another DevOps best practices 2019. In the continuous delivery approach, the developers
update the newly developed code and get them tested at varying stages using the manual as well as automated
testing. After the successful code passes all the tests, it enters the production stage.

Continuous delivery helps the development team in building, testing, as well as releasing applications much faster. It
enables the organizations to reduce the manual works, minimize failure risks, and increase deliveries of software
with a short development cycle.
ALIK SARKAR
018
10. Automated Dashboards

Automated Dashboards is the optimum way of leveraging the intelligence of DevOps. It is one of the AWS DevOps
best practices. There are two aspects of automated dashboards, which are development intelligence and operational
intelligence. It helps in providing reports in greater detail and deeper insights for better success. It enables reviewing
the configuration changes that are made to the server and database across the system.

The automated dashboards offer real-time insights to the governance team of an organization. It behaves like a
centralized hub, enabling the operation team to select the right automation tools with the help of real-time data
insights. It offers a holistic view of the changes that take place in the system, making it one of the DevOps best
practices.

11. Application Monitoring

Application monitoring is one of the Azure DevOps best practices. It helps in optimizing the application
performance that is deployed on the local data center or the cloud platform. The technology infrastructure includes
the application servers, operating systems, and communication services that can be easily leveraged with the use of
the monitoring tools. Proactive monitoring by the development team helps in enhancing application performance.
However, there is a need for the development team to become aware of the operational requirement for optimum
application monitoring.

13. Importance of Linux in DevOps


Linux is an open-source Operating System released under the GNU general public license. This allows
anyone to modify, view, and even redistribute Linux systems if they so desire. “Linux was developed by a
Finnish programming student who developed his operating system based on the old UNIX operating
system.
The customization aspect of Linux is of particular importance for DevOps. It allows for design and
security applications specific to a particular development environment or development goals to be
created. There is much more freedom over how the operating system functions compared to Windows.
Ubuntu is often, and for good reason, considered at the top of the list when this topic is discussed.
Although no official statistics are available for Linux use and implementation it can be said with some
degree of certainty that Ubuntu is the most widely used Linux distribution in the world. Because of this,
there is a wide array of free, open-sourced, software tools available to Linux based DevOps practitioners.
Those that are not free will be only a fraction of the price of similar software available on the Windows
platform.
Because of Ubuntu’s large distribution, it has very strong community support and also offers the option of
commercial support should one desire it.

14.Basic Linux commands (list provided)


1. pwd command

Use the pwd command to find out the path of the current working directory (folder) you’re in. The command will
return an absolute (full) path, which is basically a path of all the directories that starts with a forward slash (/). An
example of an absolute path is /home/username.

2. cd command
ALIK SARKAR
018
To navigate through the Linux files and directories, use the cd command. It requires either the full path or the name
of the directory, depending on the current working directory that you’re in.

Let’s say you’re in /home/username/Documents and you want to go to Photos, a subdirectory of Documents. To
do so, simply type the following command: cd Photos.

Another scenario is if you want to switch to a completely new directory, for example,/home/username/Movies. In
this case, you have to type cd followed by the directory’s absolute path: cd /home/username/Movies.

There are some shortcuts to help you navigate quickly:

• cd .. (with two dots) to move one directory up

• cd to go straight to the home folder

• cd- (with a hyphen) to move to your previous directory

On a side note, Linux’s shell is case sensitive. So, you have to type the name’s directory exactly as it is.

3. ls command

The ls command is used to view the contents of a directory. By default, this command will display the contents of
your current working directory.

If you want to see the content of other directories, type ls and then the directory’s path. For example,
enter ls /home/username/Documents to view the content of Documents.

There are variations you can use with the ls command:

• ls -R will list all the files in the sub-directories as well

• ls -a will show the hidden files

• ls -al will list the files and directories with detailed information like the permissions, size, owner, etc.

4. cat command

cat (short for concatenate) is one of the most frequently used commands in Linux. It is used to list the contents of a
file on the standard output (sdout). To run this command, type cat followed by the file’s name and its extension. For
instance: cat file.txt.

Here are other ways to use the cat command:

• cat > filename creates a new file

• cat filename1 filename2>filename3 joins two files (1 and 2) and stores the output of them in a new file (3)

• to convert a file to upper or lower case use, cat filename | tr a-z A-Z >output.txt

5. cp command

Use the cp command to copy files from the current directory to a different directory. For instance, the command cp
scenery.jpg /home/username/Pictures would create a copy of scenery.jpg (from your current directory) into
the Pictures directory.

6. mv command

The primary use of the mv command is to move files, although it can also be used to rename files.
ALIK SARKAR
018
The arguments in mv are similar to the cp command. You need to type mv, the file’s name, and the destination’s
directory. For example: mv file.txt /home/username/Documents.

To rename files, the Linux command is mv oldname.ext newname.ext

7. mkdir command

Use mkdir command to make a new directory — if you type mkdir Music it will create a directory called Music.

There are extra mkdir commands as well:

• To generate a new directory inside another directory, use this Linux basic command mkdir Music/Newfile

• use the p (parents) option to create a directory in between two existing directories. For example, mkdir -p
Music/2020/Newfile will create the new “2020” file.

8. rmdir command

If you need to delete a directory, use the rmdir command. However, rmdir only allows you to delete empty
directories.

9. rm command

The rm command is used to delete directories and the contents within them. If you only want to delete the directory
— as an alternative to rmdir — use rm -r.

Note: Be very careful with this command and double-check which directory you are in. This will delete everything
and there is no undo.

10. touch command

The touch command allows you to create a blank new file through the Linux command line. As an example, enter
touch /home/username/Documents/Web.html to create an HTML file entitled Web under
the Documents directory.

11. locate command

You can use this command to locate a file, just like the search command in Windows. What’s more, using the -
i argument along with this command will make it case-insensitive, so you can search for a file even if you don’t
remember its exact name.

To search for a file that contains two or more words, use an asterisk (*). For example, locate -i
school*note command will search for any file that contains the word “school” and “note”, whether it is uppercase or
lowercase.

12. find command

Similar to the locate command, using find also searches for files and directories. The difference is, you use
the find command to locate files within a given directory.

As an example, find /home/ -name notes.txt command will search for a file called notes.txt within the home
directory and its subdirectories.

Other variations when using the find are:

• To find files in the current directory use, find . -name notes.txt

• To look for directories use, / -type d -name notes. txt

13. grep command


ALIK SARKAR
018
Another basic Linux command that is undoubtedly helpful for everyday use is grep. It lets you search through all
the text in a given file.

To illustrate, grep blue notepad.txt will search for the word blue in the notepad file. Lines that contain the searched
word will be displayed fully.

14. sudo command

Short for “SuperUser Do”, this command enables you to perform tasks that require administrative or root
permissions. However, it is not advisable to use this command for daily use because it might be easy for an error to
occur if you did something wrong.

15. df command

Use df command to get a report on the system’s disk space usage, shown in percentage and KBs. If you want to see
the report in megabytes, type df -m.

16. du command

If you want to check how much space a file or a directory takes, the du (Disk Usage) command is the answer.
However, the disk usage summary will show disk block numbers instead of the usual size format. If you want to see
it in bytes, kilobytes, and megabytes, add the -h argument to the command line.

17. head command

The head command is used to view the first lines of any text file. By default, it will show the first ten lines, but you
can change this number to your liking. For example, if you only want to show the first five lines, type head -n 5
filename.ext.

18. tail command

This one has a similar function to the head command, but instead of showing the first lines, the tail command will
display the last ten lines of a text file. For example, tail -n filename.ext.

19. diff command

Short for difference, the diff command compares the contents of two files line by line. After analyzing the files, it
will output the lines that do not match. Programmers often use this command when they need to make program
alterations instead of rewriting the entire source code.

The simplest form of this command is diff file1.ext file2.ext

20. tar command

The tar command is the most used command to archive multiple files into a tarball — a common Linux file format
that is similar to zip format, with compression being optional.

This command is quite complex with a long list of functions such as adding new files into an existing archive, listing
the content of an archive, extracting the content from an archive, and many more. Check out some practical
examples to know more about other functions.

21. chmod command

chmod is another Linux command, used to change the read, write, and execute permissions of files and directories.
As this command is rather complicated, you can read the full tutorial in order to execute it properly.

22. chown command


ALIK SARKAR
018
In Linux, all files are owned by a specific user. The chown command enables you to change or transfer the
ownership of a file to the specified username. For instance, chown linuxuser2 file.ext will make linuxuser2 as the
owner of the file.ext.

23. jobs command

jobs command will display all current jobs along with their statuses. A job is basically a process that is started by
the shell.

24. kill command

If you have an unresponsive program, you can terminate it manually by using the kill command. It will send a
certain signal to the misbehaving app and instructs the app to terminate itself.

There is a total of sixty-four signals that you can use, but people usually only use two signals:

• SIGTERM (15) — requests a program to stop running and gives it some time to save all of its progress. If
you don’t specify the signal when entering the kill command, this signal will be used.

• SIGKILL (9) — forces programs to stop immediately. Unsaved progress will be lost.

Besides knowing the signals, you also need to know the process identification number (PID) of the program you
want to kill. If you don’t know the PID, simply run the command ps ux.

After knowing what signal you want to use and the PID of the program, enter the following syntax:

kill [signal option] PID.

25. ping command

Use the ping command to check your connectivity status to a server. For example, by simply entering ping
google.com, the command will check whether you’re able to connect to Google and also measure the response time.

26. wget command

The Linux command line is super useful — you can even download files from the internet with the help of
the wget command. To do so, simply type wget followed by the download link.

27. uname command

The uname command, short for Unix Name, will print detailed information about your Linux system like the
machine name, operating system, kernel, and so on.

28. top command

As a terminal equivalent to Task Manager in Windows, the top command will display a list of running processes
and how much CPU each process uses. It’s very useful to monitor system resource usage, especially knowing which
process needs to be terminated because it consumes too many resources.

29. history command

When you’ve been using Linux for a certain period of time, you’ll quickly notice that you can run hundreds of
commands every day. As such, running history command is particularly useful if you want to review the commands
you’ve entered before.

30. man command


ALIK SARKAR
018
Confused about the function of certain Linux commands? Don’t worry, you can easily learn how to use them right
from Linux’s shell by using the man command. For instance, entering man tail will show the manual instruction of
the tail command.

31. echo command

This command is used to move some data into a file. For example, if you want to add the text, “Hello, my name is
John” into a file called name.txt, you would type echo Hello, my name is John >> name.txt

32. zip, unzip command

Use the zip command to compress your files into a zip archive, and use the unzip command to extract the zipped
files from a zip archive.

33. hostname command

If you want to know the name of your host/network simply type hostname. Adding a -i to the end will display the IP
address of your network.

34. useradd, userdel command

Since Linux is a multi-user system, this means more than one person can interact with the same system at the same
time. useradd is used to create a new user, while passwd is adding a password to that user’s account. To add a new
person named John type, useradd John and then to add his password type, passwd 123456789.

To remove a user is very similar to adding a new user. To delete the users account type, userdel UserName

15.Git Commands (git init, git clone, git add, git commit, git diff, git reset
git status, , git rm, git log, git show, git tag, git branch, git checkout
git merge, git remote, git push, git pull) .

git config
Usage: git config –global user.name “[name]”

Usage: git config –global user.email “[email address]”

This command sets the author name and email address respectively to be used with your commits.

git init
Usage: git init [repository name]

This command is used to start a new repository.


ALIK SARKAR
018

git clone
Usage: git clone [url]
This command is used to obtain a repository from an existing URL.

git add
Usage: git add [file]

This command adds a file to the staging area.

Usage: git add *

This command adds one or more to the staging area.

git commit
Usage: git commit -m “[ Type in the commit message]”

This command records or snapshots the file permanently in the version history.

Usage: git commit -a

This command commits any files you’ve added with the git add command and also commits any
files you’ve changed since then.
ALIK SARKAR
018

git diff
Usage: git diff

This command shows the file differences which are not yet staged.

Usage: git diff –staged

This command shows the differences between the files in the staging area and the latest version present.

Usage: git diff [first branch] [second branch]

This command shows the differences between the two branches mentioned.

git reset
Usage: git reset [file]

This command unstages the file, but it preserves the file contents.
ALIK SARKAR
018

Usage: git reset [commit]

This command undoes all the commits after the specified commit and preserves the changes
locally.

Usage: git reset –hard [commit] This command discards all history and goes back to the specified
commit.

git status
Usage: git status

This command lists all the files that have to be committed.

git rm
Usage: git rm [file]

This command deletes the file from your working directory and stages the deletion.

git log
Usage: git log

This command is used to list the version history for the current branch.
ALIK SARKAR
018

Usage: git log –follow[file]

This command lists version history for a file, including the renaming of files also.

git show
Usage: git show [commit]

This command shows the metadata and content changes of the specified commit.

git tag
Usage: git tag [commitID]

This command is used to give tags to the specified commit.


ALIK SARKAR
018

git branch
Usage: git branch

This command lists all the local branches in the current repository.

Usage: git branch [branch name]

This command creates a new branch.

Usage: git branch -d [branch name]

This command deletes the feature branch.

git checkout
Usage: git checkout [branch name]

This command is used to switch from one branch to another.

Usage: git checkout -b [branch name]

This command creates a new branch and also switches to it.

git merge
Usage: git merge [branch name]

This command merges the specified branch’s history into the current branch.
ALIK SARKAR
018

git remote
Usage: git remote add [variable name] [Remote Server Link]

This command is used to connect your local repository to the remote server.

git push
Usage: git push [variable name] master

This command sends the committed changes of master branch to your remote repository.

Usage: git push [variable name] [branch]

This command sends the branch commits to your remote repository.

Usage: git push –all [variable name]

This command pushes all branches to your remote repository.

Usage: git push [variable name] :[branch name]

This command deletes a branch on your remote repository.


ALIK SARKAR
018

git pull
Usage: git pull [Repository Link]

This command fetches and merges changes on the remote server to your working directory.

git stash
Usage: git stash save

This command temporarily stores all the modified tracked files.

Usage: git stash pop

This command restores the most recently stashed files.

Usage: git stash list

This command lists all stashed changesets.

Usage: git stash drop

This command discards the most recently stashed changeset.


ALIK SARKAR
018

16. Difference between CVCS and DVCS


Centralized Version Control

Centralized Version Control is a version control system using server/client model and server contains all the
history of source code.

Distributed Version Control

Distributed Version Control is a version control where each client can have same copy of source code as server
has and both server and client maintain history of source code.

Following are the important difference between Centralized Version Control and Distributed Version Control.

Sr. Key Centralized Version Control Distributed Version Control


No.

Working In CVS, a client need to get local In DVS, each client can have a local
copy of source from server, do the branch as well and have a complete
1 changes and commit those changes history on it. Client need to push the
to centeral source on server. changes to branch which will then be
pushed to server repository.

Learning CVS systems are easy to learn and DVS systems are difficult for beginners.
2 Curve set up. Multiple commands needs to be
remembered.

Branches Working on branches in difficult in Working on branches in easier in DVS.


3 CVS. Developer often faces merge Developer faces lesser conflicts.
conflicts.

Offline CVS system do not provide offline DVD systems are workable offline as a
4 Access access. client copies the entire repository on their
local machine.

Speed CVS is slower as every command DVS is faster as mostly user deals with
5 need to communicate with server. local copy without hitting server
everytime.

Backup If CVS Server is down, developers If DVS server is down, developer can
6
cannot work. work using their local copies.
ALIK SARKAR
018

17.What is Git?

Git is a version control system used for tracking changes in computer files. It is generally used for source code
management in software development.

• Git is used to tracking changes in the source code

• The distributed version control tool is used for source code management

• It allows multiple developers to work together

• It supports non-linear development through its thousands of parallel branches

Features of Git

• Tracks history

• Free and open source

• Supports non-linear development

• Creates backups

• Scalable

• Supports collaboration

• Branching is easier

• Distributed development

Git Workflow

The Git workflow is divided into three states:

• Working directory - Modify files in your working directory

• Staging area (Index) - Stage the files and add snapshots of them to your staging area
ALIK SARKAR
018

• Git directory (Repository) - Perform a commit that stores the snapshots permanently to your Git directory.
Checkout any existing version, make changes, stage them and commit.

Branch in Git

Branch in Git is used to keep your changes until they are ready. You can do your work on a branch while the main
branch (master) remains stable. After you are done with your work, you can merge it with the main office.

18.What is a version control system and its types?


Version Control System:

Version Control Systems are process management systems which maintain changes recorded in a file or set of files
over period of time. Each change is maintained as a version. Users can track specific versions later. Version control
systems are also called as revision control systems. Revision control systems work as independent standalone
applications. Applications like spreadsheets and word processors have control mechanisms. The unique features of
version control system/ revision control system are as follows:

Up to date history is available for the document and file types.


It does not require any other repository systems.
The repositories can be cloned as per the need and availability. This is extremely helpful in case of failure and
accidental deletions.
VCS includes tag system which helps in differentiating between alpha, beta or various release versions for different
documents.

For example, changes made in code base among developers include version control system for tracking changes
with specific lines.

The various types of the version control systems are:


1. Local Version Control System
2. Centralized Version Control System
3. Distributed Version Control System

1. Local Version Control System:


ALIK SARKAR
018

Local version control system maintains track of files within the local system. This approach is very common and
simple. This type is also error prone which means the chances of accidentally writing to the wrong file is higher.

2. Centralized Version Control Systems

In this approach, all the changes in the files are tracked under the centralized server. The centralized server includes
all the information of versioned files, and list of clients that check out files from that central place.
Example: Tortoise SVN

3. Distributed Version Control System:

Distributed version control systems come into picture to overcome the drawback of centralized version control
system. The clients completely clone the repository including its full history. If any server dies, any of the client
repositories can be copied on to the server which help restore the server.

Every clone is considered as a full backup of all the data.


Example: Git
ALIK SARKAR
018

19.What is Chef?
• CHEF is a configuration management tool written in Ruby and Erlang. It is used to configure and maintain
a company's servers.

• "Chef helps you express your infrastructure policy – how your software is delivered and maintained on
your servers – as code.

• When infrastructure is code, it becomes more maintainable, versionable, testable, and collaborative."

• Chef is a Configuration management tool that manages the infrastructure by writing code rather than using
a manual process so that it can be automated, tested and deployed very easily.

• Chef has Client-server architecture and it supports multiple platforms like Windows, Ubuntu, Centos, and
Solaris etc.

• It can also be integrated with cloud platform like AWS, Google Cloud Platform, and Open Stack etc.

• suppose you have shifted your office into a different environment and you wanted your system
administrator to install, update and deploy software on hundreds of system overnight.

• When the system engineer does this task manually it may cause Human errors and some software’s may not
function properly.

• At this stage, we use Chef which is a powerful automated tool which transfers infrastructure into code.

20.Explain Working of chef.


• Accelerating software delivery, when your infrastructure is automated all the software requirements like
testing, creating new environments for software deployments etc. becomes faster.

• Increased service Resiliency, by making the infrastructure automated it monitors for bugs and errors
before they occur it can also recover from errors more quickly.

• Risk Management, chef lowers risk and improves compliance at all stages of deployment. It reduces the
conflicts during the development and production environment.

• Cloud Adoption, Chef can be easily adapted to a cloud environment and the servers and infrastructure can
be easily configured, installed and managed automatically by Chef.

• Managing Data Centers and Cloud Environments, as discussed earlier Chef can run on different
platforms, under chef you can manage all your cloud and on-premise platforms including servers.

• Streamlined IT operation and Workflow, Chef provides a pipeline for continuous deployment starting
from building to testing and all the way through delivery, monitoring, and troubleshooting.

• Chef works on a three-tier client server model wherein the working units such as cookbooks are developed
on the Chef workstation.

• From the command line utilities such as knife, they are uploaded to the Chef server and all the nodes which
are present in the architecture are registered with the Chef server.
ALIK SARKAR
018

21.Chef Terminology (chef workstation, chef server, chef node, cookbook,


recipe)

• Chef Workstation

• This is the location where all the configurations are developed.

• Chef workstation is installed on the local machine.

• The workstation is used to interact with Chef-server and also to interact with Chef-nodes.

• It is also used to create Cookbooks.

• Workstation is a place where all the interaction takes place where Cookbooks are created, tested and
deployed, and in workstation, codes are tested.

• Workstation is also used for defining roles and environments based on the development and production
environment.

• Some components of workstation are

• Development Kit it contains all the packages requires for using Chef

• Chef Command line tool is a place where cookbooks are created, tested and deployed and through this
policies are uploaded to Chef Server.

• Knife is used for interacting with Chef Nodes.

• Test Kitchen is for validating Chef Code

• Chef-Repo is a repository in which cookbooks are created, tested and maintained though Chef Command
line tool.
ALIK SARKAR
018

• Recipe

• It can be defined as a collection of attributes which are used to manage the infrastructure. These attributes
which are present in the recipe are used to change the existing state or setting a particular infrastructure
node.

• They are loaded during Chef client run and comparted(divide & share) with the existing attribute of the
node (machine).

• It then gets to the status which is defined in the node resource of the recipe. It is the main workhorse of the
cookbook.

• Cookbook

• A cookbook is a collection of recipes. They are the basic building blocks which get uploaded to Chef
server. When Chef run takes place, it ensures that the recipes present inside it gets a given infrastructure to
the desired state as listed in the recipe.

• Cookbooks are created using Ruby language and Domain Specific languages are used for specific
resources.

• Chef Server
• This works as a centralized working unit of Chef setup, where all the configuration files are uploaded post
development. There are different kinds of Chef server, some are hosted Chef server whereas some are built-
in premise.

• Chef server contains all configuration data and it stores cookbooks, recipes, and metadata that describe
each node in the Chef-Client.

• Configuration details are given to node through Chef-Client

• Prior to pushing the changes, it verifies that the nodes and workstation are paired with the server through
the use of authorization keys, and then allow for communication between workstations and nodes.

• Chef Nodes
• They are the actual machines which are going to be managed by the Chef server.

• All the nodes can have different kinds of setup as per requirement.

• Chef client is the key component of all the nodes, which helps in setting up the communication between
the Chef server and Chef node.

• The other components of Chef node is Ohai, which helps in getting the current state of any node at a given
point of time.

• Nodes are managed by Chef and each node is configured by installing Chef-Client on it.
ALIK SARKAR
018
• Chef-Nodes are a machine such as physical, virtual cloud etc.

• Chief-Client is for registering and authenticating node, building node objects and for configuration of the
nodes.

• Chief-client runs locally on every node to configure the node.

• Ohai is used for determining the system state at beginning of Chef run in Chef-Client. It Collects. All the
system configuration data.

22.What is infrastructures as a code.


• Infrastructure as Code can be explained from a high level in three simple steps and visualized with the
diagram below.

• Developers write the infrastructure specification in a domain-specific language.

• The resulting files are sent to a master server, a management API, or a code repository.

• The platform takes all the necessary steps to create and configure the computer resources.

• Types of Infrastructure as Code

• There are four main types of IaC that developers can choose from:

• Scripting: Writing scripts is the most direct approach to IaC. Ad-hoc scripts are best for executing simple,
short, or one-off tasks. For complex setups, however, it's best to use a more specialized alternative.

• Configuration management tools: Also known as configuration as code, these are specialized tools
designed to manage software. They usually focus on installing and configuring servers. Examples of these
tools are Chef, Puppet, and Ansible.

• Provisioning tools: Provisioning tools focus on creating infrastructure. Using these types of tools,
developers can define exact infrastructure components. Examples of this are Terraform, AWS
CloudFormation, and OpenStack Heat.

• Containers and templating tools: These tools generate templates or images pre-loaded with all the
libraries and components required to run an application. Containerized workloads are easy to distribute and
have much lower overhead than running a full-size server. Examples are Docker, rkt, Vagrant, and Packer.
ALIK SARKAR
018
• There are two models of configuration Management tools – PUSH-based & PULL-based. In the PUSH-
based, the Master server pushes the configuration code to the servers wherein PULL-based individual
servers contact the Master for getting configuration code. PUPPET and CHEF are widely used PULL-
based models, ANSIBLE is a popular PUSH-based model. In this article, we will see about CHEF.

23.What are Databags? How to create and manage databags?


A data bag is a container for items that represent information about your
infrastructure that is not tied to a single node. Data bags contain information that
needs to be shared among more than one node. For example: Shared passwords.

To add a data bag:


1. Open the Chef management console.
2. Click Policy.
3. Click Data Bags.
4. Click Create.
5. In the Create a Data Bag dialog box, enter the name of the data bag.

6. Click Create Data Bag.


Manage Items
A data bag is a container of related data bag items, where each individual data bag item is a JSON file. knife
can load a data bag item by specifying the name of the data bag to which the item belongs and then the
filename of the data bag item. The only structural requirement of a data bag item is that it must have an id:
{
/* This is a supported comment style */
// This style is also supported
"id": "ITEM_NAME",
"key": "value"
}
where

• key and value are the key:value pair for each additional attribute within the data bag item
• /* ... */ and // ... show two ways to add comments to the data bag item
ALIK SARKAR
018

Add Item
To add a data bag item:
1. Open the Chef management console.
2. Click Policy.
3. Click Data Bags.
4. Select a data bag.
5. Click Create Item.
6. In the Create a Data Bag Item dialog box,
enter the data bag identifier, and then JSON
data that defines the data bag item.
7. Click Create Data Bag Item.
Delete Item
To delete a data bag item:
1. Open the Chef management console.
2. Click Policy.
3. Click Data Bags.
4. Select a data bag.
5. Select the Items tab.
6. Select a data bag.
7. Click Delete.
Edit Item
To edit a data bag item:
1. Open the Chef management console.
2. Click Policy.
3. Click Data Bags.
4. Select a data bag.
5. Select the Items tab.
6. Select a data bag.
7. Click Edit.
8. Make your changes.
9. Click Save Item.
View Item
To view data bag items for a data bag:

1. Open the Chef management console.


2. Click Policy.
3. Click Data Bags.
4. Select a data bag.
5. Select the Items tab.
ALIK SARKAR
018

24.How to configure knife?

We now have to configure the knife command. This command is the central way of
communicating with our server and the nodes that we will be configuring. We need to tell
it how to authenticate and then generate a user to access the Chef server.
Luckily, we’ve been laying the groundwork for this step by acquiring the appropriate credential
files. We can start the configuration by typing:

knife configure --initial


This will ask you a series of questions. We will go through them one by one:

WARNING: No knife configuration file found Where should I put the config file?
[/home/your_user/.chef/knife.rb]
The values in the brackets ([]) are the default values that knife will use if we do not select a
value.

We want to place our knife configuration file in the hidden directory we have been using:

/home/your_user/chef-repo/.chef/knife.rb
In the next question, type in the domain name or IP address you use to access the Chef server.
This should begin with https:// and end with :443:
https://server_domain_or_IP:443
You will be asked for a name for the new user you will be creating. Choose something
descriptive:

Please enter a name for the new user: [root] station1


It will then ask you for the admin name. This you can just press enter on to accept the default
value (we didn’t change the admin name).

It will then ask you for the location of the existing administrators key. This should be:

/home/your_user/chef-repo/.chef/admin.pem
It will ask a similar set of questions about the validator. We haven’t changed the validator’s
name either, so we can keep that as chef-validator. Press enter to accept this value.
It will then ask you for the location of the validation key. It should be something like this:
ALIK SARKAR
018
/home/your_user/chef-repo/.chef/chef-validator.pem
Next, it will ask for the path to the repository. This is the chef-repo folder we have been operating
in:
/home/your_user/chef-repo
Finally, it will ask you to select a password for your new user. Select anything you would like.

This should complete our knife configuration. If we look in our chef-repo/.chef directory, we
should see a knife configuration file and the credentials of our new user:
ls ~/chef-repo/.chef
admin.pem chef-validator.pem knife.rb station1.pem

25.How to create roles and add roles to organization


Roles in Chef are a logical way of grouping nodes. Typical cases are to have roles for web
servers, database servers, and so on. One can set custom run list for all the nodes and override
attribute value within roles.

Create a Role
vipin@laptop:~/chef-repo $ subl roles/web_servers.rb
name "web_servers"
description "This role contains nodes, which act as web servers"
run_list "recipe[ntp]"
default_attributes 'ntp' => {
'ntpdate' => {
'disable' => true
}
}

# Create the chef-repo directory on the workstation. This directory will be used as the working path.
$ mkdir /chef-repo
# Create the .chef directory. This directory will be used to store the Chef configuration file for the workstation.
$ mkdir –p /chef-repo/.chef
# Create Chef configuration file knife.rb in the /chef-repo/.chef0 directory.
log_level :info
log_location STDOUT
node_name 'admin'
client_key '/root/chef-repo/.chef/admin.pem'
validation_key '/root/chef-repo/.chef/admin_org.pem'
chef_server_url 'https://chef-server:443/organizations/abc'
# Use TFTP or FTP to download the key files for the workstation from the Chef server to the /chef-
repo/.chef directory on the workstation. (Details not shown.)
# Create resource directory netdev.
ALIK SARKAR
018
$ knife cookbook create netdev
After the command is executed, the netdev directory is created in the current directory. The directory contains files
and subdirectories for the resource. The recipes directory stores the resource file.
# Create resource file default.rb in the recipes directory.
netdev_vlan 'vlan3' do
vlan_id 3
action :create
end
# Upload the resource file to the Chef server.
$ knife cookbook upload –all

26.What are attributes? How to add custom attributes to cookbook?

An attribute is a specific detail about a node. Attributes are used by Chef Infra Client to understand:

• The current state of the node


• What the state of the node was at the end of the previous Chef Infra Client run
• What the state of the node should be at the end of the current Chef Infra Client run

Attributes are defined by:

• The node as saved on the Chef Infra Server


• Attributes passed using JSON on the command line
• Cookbooks (in attribute files and/or recipes)
• Policyfiles

custom Chef Cookbook and have defined a custom attribute called default["server"]["apikey"] = nil thats
been defined within the cookbook in a separate attributes file that looks like this:

#Default Attributes
default["webhooks"]["get_response"] = ""
default["webhooks"]["put_response"] = ""
default["webhooks"]["post_response"] = ""

default["server"]["username"] = "user"
default["server"]["password"] = "123"

default["server"]["apikey"] = nil
Within my recipe I then do this:

webhooks_request "Request an API key from TPP " do


uri "172.16.28.200/sdk/authorize/"
post_data (
{ 'Username' => node["server"]["username"], 'Password' => node["server"]["password"]}
)
header_data (
{ 'content-type' => 'application/json'}
)
ALIK SARKAR
018
expected_response_codes [ 200, 201, 400 ]
action :post
end
I then follow this with ruby_block that updates the value of the ``default["server"]["apikey"]` attribute
with the API key like this:

27.What is POM in maven?


• POM stands for Project Object Model. It is fundamental unit of work in Maven. It is an XML file
that resides in the base directory of the project as pom.xml.
• The POM contains information about the project and various configuration detail used by Maven
to build the project(s).
• When executing a task or goal, Maven looks for the POM in the current directory. It reads the
POM, gets the needed configuration information, then executes the goal.
• Some of the configuration that can be specified in the POM are the project dependencies, the
plugins or goals that can be executed, the build profiles, and so on. Other information such as the
project version, description, developers, mailing lists and such can also be specified.

28.What elements are used for creating a pom.xml file?


The architecture of a Maven project consists of a project directory with a POM file (pom.xml)
containing all project information at the root and one /src folder containing the source code (in
/main) and the test files (in /test). The POM file is used by Maven program (mvn) to build your
project.
ALIK SARKAR
018

29.What are the different types of Maven repositories?


• A repository in Maven holds build artifacts and dependencies of varying types.
• There are exactly two types of repositories: local and remote:
• the local repository is a directory on the computer where Maven runs. It caches remote
downloads and contains temporary build artifacts that you have not yet released.
remote repositories refer to any other type of repository, accessed by a variety of protocols such
as file:// and https://.
These repositories might be a truly remote repository set up by a third party to provide their artifacts for
downloading (for ex, repo.maven.apache.org). Other "remote" repositories may be internal repositories
set up on a file or HTTP server within your company, used to share private artifacts between development
teams and for releases.
• The default local repository is located in theC:/Users/superdev/.m2 folder under the home
directory of the user.
• If an artifact or a plugin is available in the local repository, Maven uses it. Otherwise, it is
downloaded from a central repository and stored in the local repository. The default central
repository is Maven Central.
Local Repository
• <settings>
• <localRepository>
• C:\M2
• </localRepository>
• </settings>
Remote Repository
• <repositories>
• <repository>
• <id>org.source.repo</id>
• <url>http://maven.orgName.com/maven2/</url>
• </repository>
• </repositories>
ALIK SARKAR
018

30.What are the different phases of the life cycle of Maven?


Maven Lifecycle: Below is a representation of the default Maven lifecycle and its 8
steps: Validate, Compile, Test, Package, Integration test, Verify, Install and Deploy.

8 Phases of the Default Maven Lifecycle


The default Maven lifecycle consists of 8 major steps or phases for compiling, testing, building and
installing a given Java project as specified below:
1. Validate: This step validates if the project structure is correct. For example – It checks if all the
dependencies have been downloaded and are available in the local repository.
2. Compile: It compiles the source code, converts the .java files to .class and stores the classes in
target/classes folder.
3. Test: It runs unit tests for the project.
4. Package: This step packages the compiled code in distributable format like JAR or WAR.
5. Integration test: It runs the integration tests for the project.
6. Verify: This step runs checks to verify that the project is valid and meets the quality standards.
7. Install: This step installs the packaged code to the local Maven repository.
8. Deploy: It copies the packaged code to the remote repository for sharing it with other developers.
Maven follows a sequential order to execute the commands where if you run step n, all steps preceding it
(Step 1 to n-1) are also executed. For example – if we run the Installation step (Step 7), it will validate,
compile, package and verify the project along with running unit and integration tests (Step 1 to 6) before
installing the built package to the local repository.

Maven Commands:
• mvn clean: Cleans the project and removes all files generated by the previous build.
• mvn compile: Compiles source code of the project.
ALIK SARKAR
018

• mvn test-compile: Compiles the test source code.


• mvn test: Runs tests for the project.
• mvn package: Creates JAR or WAR file for the project to convert it into a distributable format.
• mvn install: Deploys the packaged JAR/ WAR file to the local repository.
• mvn deploy: Copies the packaged JAR/ WAR file to the remote repository after compiling,
running tests and building the project.

31.What are Maven plugins used for? What are the types of Maven plugins?
"Maven" is really just a core framework for a collection of Maven Plugins. In other words, plugins are
where much of the real action is performed, plugins are used to: create jar files, create war files,
compile code, unit test code, create project documentation, and on and on.

in Maven, there are two kinds of plugins, build and reporting:


• Build plugins are executed during the build and configured in the <build/> element.
• Reporting plugins are executed during the site generation and configured in the
<reporting/> element.

32.In Maven, what is a snapshot?


A Maven snapshot is a special version of a Maven package that refers to the latest production
branch code.
It is a development version that precedes the final release version.
You can identify a snapshot version of a Maven package by the suffix SNAPSHOT that is appended to
the package version.
For example, the snapshot of version 1.1 is 1.1-SNAPSHOT.
A snapshot version in Maven is one that has not been released.
The difference between a "real" version and a snapshot version is that snapshots might get updates. That
means that downloading 1.0-SNAPSHOT today might give a different file than downloading it yesterday
or tomorrow.
snapshot dependencies should only exist during development and no released version
ALIK SARKAR
018

33.What are the locations where Maven dependencies are stored?


It is located in MAVEN_HOME/conf/settings. xml, for example: E:\apache-maven-3.1.
Maven supports three types of repositories:

• Local – Folder location on the local Dev machine


• Central – Repository provided by Maven community
• Remote – Organization owned custom repository

Now let's focus on the local repository.

1. The Local Repository


Maven's local repository is a directory on the local machine that stores all the project artifacts.
When we execute a Maven build, Maven automatically downloads all the dependency jars into the
local repository. Usually, this directory is named .m2.
Here's where the default local repository is located based on OS:
Windows: C:\Users\<User_Name>\.m2
Linux: /home/<User_Name>/.m2
Mac: /Users/<user_name>/.m2
And for Linux and Mac, we can write in the short form:
~/.m2

2. Custom Local Repository in settings.xml


If the repo isn't present in this default location, it's likely because of some pre-existing
configuration.
That config file is located in the Maven installation directory in a folder called conf, with the
name settings.xml.
Here's the relevant configuration that determines the location of our missing local repo:
<settings>
<localRepository>C:/maven_repository</localRepository>
...
This is essentially how we can change the location of the local repo. Of course, if we change that
location, we'll no longer find the repo at the default location.
The files stored in the earlier location won't be moved automatically.
ALIK SARKAR
018

3. Passing Local Repository Location via Command Line


Apart from setting the custom local repository in Maven's settings.xml, the mvn command supports
the maven.repo.local property, which allows us to pass the local repository location as a command-line
parameter:
mvn -Dmaven.repo.local=/my/local/repository/path clean install
In this way, we don't have to change Maven's settings.xml.

34. List out the dependency scope in Maven?


Maven dependency scope attribute is used to specify the visibility of a dependency, relative to the
different lifecycle phases (build, test, runtime etc). Maven provides six scopes
i.e. compile, provided, runtime, test, system, and import.

Maven dependency scope – compile


This is maven default scope. Dependencies with compile scope are needed to build, test, and run the
project.
Scope compile is to be required in most of the cases to resolve the import statements into your java
classes sourcecode.
<dependencies>

<dependency>

<groupId>log4j</groupId>

<artifactId>log4j</artifactId>

<version>1.2.14</version>

<!-- You can ommit this because it is default -->

<scope>compile</scope>

</dependency>

</dependencies>

Maven dependency scope – provided


Maven dependency scope provided is used during build and test the project. They are also required to
run, but should not exported, because the dependency will be provided by the runtime, for instance, by
servlet container or application server.
ALIK SARKAR
018

<dependency>

<groupId>javax.servlet</groupId>

<artifactId>servlet-api</artifactId>

<version>3.0.1</version>

<scope>provided</scope>

</dependency>

Maven dependency scope – runtime


Dependencies with maven dependency scope runtime are not needed to build, but are
part of the classpath to test and run the project.

<dependency>

<groupId>com.thoughtworks.xstream</groupId>

<artifactId>xstream</artifactId>

<version>1.4.4</version>

<scope>runtime</scope>

</dependency>

Maven dependency scope – test


Dependencies with maven dependency scope test are not needed to build and run the
project. They are needed to compile and run the unit tests.

<dependency>

<groupId>junit</groupId>

<artifactId>junit</artifactId>

<version>4.12</version>

<scope>test</scope>
ALIK SARKAR
018

</dependency>

Maven dependency scope – system


Dependencies with system are similar to ones with scope provided. The only
difference is system dependencies are not retrieved from remote repository. They are
present under project’s subdirectory and are referred from there. See external
dependency for more detail.

<dependency>

<groupId>extDependency</groupId>

<artifactId>extDependency</artifactId>

<scope>system</scope>

<version>1.0</version>

<systemPath>${basedir}\war\WEB-INF\lib\extDependency.jar</systemPath>

</dependency>

Maven dependency scope – import


import scope is only supported on a dependency of type pom in
the dependencyManagement section. It indicates the dependency to be replaced with
the effective list of dependencies in the specified
POM’s dependencyManagement section.

<dependencyManagement>

<dependencies>

<dependency>

<groupId>other.pom.group.id</groupId>

<artifactId>other-pom-artifact-id</artifactId>

<version>SNAPSHOT</version>
ALIK SARKAR
018

<scope>import</scope>

<type>pom</type>

</dependency>

</dependencies>

</dependencyManagement>

Maven dependency transitivity resolution


When you include a maven dependency and it has it’s own other dependencies (i.e. transitive
dependencies) then you may want to be clear about the scope of these transitive dependencies as well.

Let’s understand about maven transitive dependencies with a simple table. In this table, if a dependency
is set to the scope in the left column, transitive dependencies at top row will result in a dependency with
the scope listed at their intersection.

35.What is Docker?
• Docker is an open platform for developing, shipping, and running applications.

• Docker enables you to separate your applications from your infrastructure so you can deliver software
quickly.

• With Docker, you can manage your infrastructure in the same ways you manage your applications.

• Docker makes it possible to easily isolate server applications into containers, control resource allocation,
and design simpler deployment pipelines.

• By taking advantage of Docker’s methodologies for shipping, testing, and deploying code quickly, you can
significantly reduce the delay between writing code and running it in production.

• Docker streamlines the development lifecycle by allowing developers to work in standardized


environments using local containers which provide your applications and services. Containers are great for
continuous integration and continuous delivery (CI/CD) workflows.

36.Explain Docker Image.


• Images

• An image is a read-only template with instructions for creating a Docker container. Often, an image
is based on another image, with some additional customization. For example, you may build an image
which is based on the mysql image, which helps to create database and tables.
ALIK SARKAR
018
• You might create your own images or you might only use those created by others and published in a
registry.

• To build your own image, you create a Dockerfile with a simple syntax for defining the steps needed to
create the image and run it. Each instruction in a Dockerfile creates a layer in the image.

• When you change the Dockerfile and rebuild the image, only those layers which have changed are rebuilt.

• This is part of what makes images so lightweight, small, and fast, when compared to other virtualization
technologies.

37.Explain Docker Container.


• A container is a runnable instance of an image. You can create, start, stop, move, or delete a
container using the Docker API or CLI.
• You can connect a container to one or more networks, attach storage to it, or even create a new
image based on its current state.
• By default, a container is relatively well isolated from other containers and its host machine.
• In an object-oriented programming analogy, an image is a class and the container is an instance of
that class. This allows operational efficiency by allowing to you to multiple containers from a
single image.
• You can control how isolated a container’s network, storage, or other underlying subsystems are
from other containers or from the host machine.
• A container is defined by its image as well as any configuration options you provide to it when
you create or start it. When a container is removed, any changes to its state that are not stored in
persistent storage disappear.
• The Docker Engine is of the core components of a Docker architecture on which the application
runs. You could also consider the Docker Engine as the application that’s installed on the system
that manages containers, images, and builds.

38.Explain Docker Hub.


• Docker Hub (link resides outside IBM) 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.
• All Docker Hub users can share their images at will. They can also download predefined base
images from the Docker filesystem to use as a starting point for any containerization project.
ALIK SARKAR
018

39.Explain the use of DockerFile.


• DockerFile

• Every Docker container starts with a simple text file containing instructions for how to build
the Docker container image. DockerFile automates the process of Docker image creation.

• It’s essentially a list of command-line interface (CLI) instructions that Docker Engine will run in order to
assemble the image.

40.Explain the Docker client-server architecture.


• Docker architecture🔗

• Docker uses a client-server architecture.

• The Docker client talks to the Docker daemon, which does the heavy lifting of building, running, and
distributing your Docker containers.

• The Docker client and daemon can run on the same system, or you can connect a Docker client to a remote
Docker daemon

• . The Docker client and daemon communicate using a REST API, over UNIX sockets or a network
interface. Another Docker client is Docker Compose, that lets you work with applications consisting of a
set of containers.

• The Docker daemon


• The Docker daemon (dockerd) listens for Docker API requests and manages Docker objects such
as images, containers, networks, and volumes. A daemon can also communicate with other
daemons to manage Docker services.
• The Docker client
• The Docker client (docker) is the primary way that many Docker users interact with Docker.
When you use commands such as docker run, the client sends these commands to dockerd, which
carries them out.
ALIK SARKAR
018

• The docker command uses the Docker API.


• The Docker client can communicate with more than one daemon.
• Docker Desktop
• Docker Desktop is an easy-to-install application for your Mac or Windows environment that
enables you to build and share containerized applications and microservices.
• Docker Desktop includes the Docker daemon (dockerd), the Docker client (docker), Docker
Compose, Docker Content Trust, Kubernetes, and Credential Helper.
• Docker registries
• A Docker registry stores Docker images. Docker Hub is a public registry that anyone can use, and
Docker is configured to look for images on Docker Hub by default. You can even run your own
private registry.
• When you use the docker pull or docker run commands, the required images are pulled from your
configured registry. When you use the docker push command, your image is pushed to your
configured registry.
• Docker objects
• When you use Docker, you are creating and using images, containers, networks, volumes,
plugins, and other objects. This section is a brief overview of some of those objects.

41.Which are the Docker Key use cases.


Docker’s Key use cases
Here are just some of the use cases that provide a consistent environment at low overhead with the
enabling technology of Docker.
1. Simplifying Configuration
The primary use case Docker advocates is simplifying configuration. One of the big advantages of VMs is
the ability to run any platform with its own config on top of your infrastructure.
Docker provides this same capability without the overhead of a virtual machine. It lets you put your
environment and configuration into code and deploy it. The same Docker configuration can also be used
in a variety of environments. This decouples infrastructure requirements from the application
environment.
The freedom to run your applications across multiple IaaS/PaaS without any extra tweaks is the ultimate
dream that Docker can help you achieve.
Today, every IaaS/PaaS provider from Amazon to Google supports Docker. The big names have placed
their bet on Docker. Now, it’s your turn to benefit from these same options.
2. Code Pipeline Management
ALIK SARKAR
018

The previous use case makes a large impact in managing the code pipeline. As the code travels from the
developer’s machine to production, there are many different environments it has to go through to get
there. Each of these may have minor differences along the way.
Docker provides a consistent environment for the application from dev through production, easing the
code development and deployment pipeline.
The immutable nature of Docker images, and the ease with which they can be spun up, help you achieve
zero change in application runtime environments across dev through production.
3. Developer Productivity
In turn, this leads to some additional advantages Docker delivers for a dev productivity use case. For a
detailed example, you can check out my talk I gave at DockerCon 2014 here.
In a developer environment, we have two goals that are at odds with each other:
• We want it be as close as possible to production; and
• We want the development environment to be as fast as possible for interactive use.
Ideally, to achieve the first goal, we need to have every service running on its own VM to reflect how the
production application runs. However, we don’t want to always require an Internet connection and add
the overhead of working remotely every time a compilation is needed.
This is where the low overhead of Docker comes in handy. A development environment usually has a low
memory capacity, and by not adding to the memory footprint that’s commonly done when using a VM,
Docker easily allows a few dozen services to run.
To achieve the second goal, to provide a fast feedback loop, we use Docker’s shared volumes to make the
application code available to the container(s) from the container’s host OS, which is a virtualbox VM
(typically, a Vagrant box). The application source code is made available to the container host OS
(Vagrant box) using Vagrant’s synced folders with the host OS (Windows, Mac or Linux).
This approach has multiple benefits. The developer can edit the source code from his platform of choice
(Windows, Mac or Linux) and is able to see the changes right away as the applications run using the same
source code with the running environment set inside of the Vagrant box using Docker container(s).
Moreover, this approach helps a front-end engineer who is not much into the back end nitty gritty to
easily use the full application setup and work on his or her area of interest without the setup or installation
blues getting in the way. And, it provides an optional opportunity for further exploration on how back-end
systems work under the hood to get a better understanding for the full stack.
There is more thought that goes into this approach. The Vagrant box we are talking about can be a vanilla
OS distro which gets fully provisioned through the Vagrantfile. Or, it could be a custom box which is pre-
provisioned to some extent and then further provisioned using Vagrantfile when we do a Vagrant up.
It’s a trade-off as is usually the case when dealing with problems of engineering. If you are wanting to
have no dependency on the network, building a custom box pre-provisioned with everything is the way to
go. The only drawback to this is a big VM box size and a non-updated environment.
One more point to consider when you want to achieve the first goal (minimize the mismatch between dev
and production) is to have a strategy for getting the database dump so that all parts of the app are covered.
ALIK SARKAR
018

This is something analogous to what we aim for in test coverage. Simply getting a random subset is not
an optimal solution. You need to have a strategy that aligns with all dependent features of your
application.
If you have the option of putting in a full database dump, that’s also a way to go. But, in these times of
big data, you can hardly afford that. You need to have a subset to work on or test.
4. App Isolation
There may be many reasons for which you end up running multiple applications on the same machine. An
example of this is the developer productivity flow described earlier. But there are other cases, too.
A couple of such cases to consider are server consolidation for decreasing cost or a gradual plan to
separate a monolithic application into decoupled pieces.
Let’s say, for example, you need to run two REST API servers, both of which use flask. But, each of them
uses a slightly different version of flask and other such dependencies. Running these API servers under
different containers provides an easy way out through what we call the “dependency hell.”
5. Server Consolidation
Just like using VMs for consolidating multiple applications, the application isolation abilities of Docker
allows consolidating multiple servers to save on cost. However, without the memory footprint of multiple
OSes and the ability to share unused memory across the instances, Docker provides far denser server
consolidation than you can get with VMs.
The new breed of highly customizable PAAS, such as Heroku, Elastic Beanstalk and App Engine, all use
these powerful feature of containers that is now at your disposal with Docker.
Moreover, open source projects like Deis, Kubernetes, Cadvisor, Panamax, and others make deploying
and monitoring large numbers of containers representing a multi-tier application architecture manageable.
6. Debugging Capabilities
Docker provides many tools that are not necessarily specific to containers, but, they work well with the
concept of containers. They also provide extremely useful functionality. This includes the ability to
checkpoint containers and container versions, as well as to diff two containers. This can be immensely
useful in fixing an application.
Flux7.com was run inside a Docker container. Our web developer told us that a crash resulted from a code
change he’d pushed from the UI to the functions.php file. Within a minute, I was able to create a dev
environment enabling the web developer to debug in a sandbox. When he gave us the green light a short
time later, we were able to switch back to the latest version of the website, thanks to Docker and Linux
Containers.
While the process was solvable using another strategy, using Docker was an efficient way to solve the
problem. And, it’s one we have implemented in a number of customer deployments where front-end
functionality is business-critical.
7. Multi-tenancy
Yet another interesting use case of Docker is its use in multi-tenant applications, thereby avoiding major
application rewrites.
ALIK SARKAR
018

Our own example is to develop quick and easy multi-tenancy for an IoT application. Code bases for such
multi-tenant applications are far more complicated, rigid and difficult to handle. Rearchitecting an
application is not only time consuming, but also costs a lot of money.
Using Docker, it was easy and inexpensive to create isolated environments for running multiple instances
of app tiers for each tenant. This was possible given the spin up speed of Docker environments and it’s
easy-to-use API, which we can use to spin containers programmatically. We used docker-py, which is a
Python library to help interact with the Docker daemon through a web application interface.
###8. Rapid Deployment
Before VMs, bringing up a new hardware resource took days. Virtualization brought this number down to
minutes. Docker, by creating just a container for the process and not booting up an OS, brings it down to
seconds. This is the enabling technology that has brought Google and Facebook to using containers.
Essentially, you can create and destroy resources in your data center without worrying about the cost of
bringing it up again. With typical data center utilization at 30%, it is easy to bump up that number by
using a more aggressive allocation of resources. And, the low cost of bringing up a new instance allows
for a more aggressive allocation of resources.
Moreover, the immutable nature of Docker images gives you the peace of mind that things will work
exactly the way they have been working and are supposed to work.
##Conclusion
There are many more documented use cases that show Docker as an appropriate solution. These span the
spectrum from security to developer empowerment. I’ve focused on the uses that we’ve seen add
significant value to real-world projects.
Feel free to add your own ideas in the comments section below.
From running API servers and web applications to running CUDA applications and full-fledged High
Definition Desktop Cloud Visualization -- where you are able to use the GPU from inside of the running
container, Docker offers a broad range of use cases. Docker has made Linux containerization technology
accessible and easy-to-use, and, more importantly, manageable
ALIK SARKAR
018

42.Difference between Docker and virtualization

43.Docker commands like docker pull, docker search, docker images, docker
run,
docker exec, docker ps, docker stop, docker restart, docker logs, docker rm,
docker rmi,

Docker search
As its help with docker search –help says, it helps search Docker hub for images. As our aim is to run MySQL locally let’s run the
following command to see what MySQL related images are available on DockerHub:

docker search mysql

This gives an output similar to the below:

NAME DESCRIPTION STARS OFFICIAL AUTOMATED


mysql MySQL is a widely used, open-source relation… 12559 [OK]
mariadb MariaDB Server is a high performing open sou… 4829 [OK]
percona Percona Server is a fork of the MySQL relati… 576 [OK]
phpmyadmin phpMyAdmin - A web interface for MySQL and M… 535 [OK]
bitnami/mysql Bitnami MySQL Docker Image 71 [OK]
linuxserver/mysql-workbench 36
linuxserver/mysql A Mysql container, brought to you by LinuxSe… 35
ubuntu/mysql MySQL open source fast, stable, multi-thread… 33
circleci/mysql MySQL is a widely used, open-source relation… 25
google/mysql MySQL server for Google Compute Engine 21 [OK]
vmware/harbor-db Mysql container for Harbor 10
bitnami/mysqld-exporter 3
ibmcom/mysql-s390x Docker image for mysql-s390x 2
newrelic/mysql-plugin New Relic Plugin for monitoring MySQL databa… 1 [OK]
ALIK SARKAR
018
nasqueron/mysql 1 [OK]
vitess/mysqlctld vitess/mysqlctld 1 [OK]
mirantis/mysql 0

It is not super useful as it is listing all the MySQL images, to make our search more useful and target we will use the filter and limit
parameters as follows:

docker search --filter=is-official=true --limit=5 mysql

Here, we are asking docker to give us only the official images and limit it to 5 for mysql. It will yield something like:

NAME DESCRIPTION STARS OFFICIAL AUTOMATED


mysql MySQL is a widely used, open-source relation… 12559 [OK]
mariadb MariaDB Server is a high performing open sou… 4829 [OK]
percona Percona Server is a fork of the MySQL relati… 576 [OK]
phpmyadmin phpMyAdmin - A web interface for MySQL and M… 535 [OK]

Looks like the official MySQL image with 12.5K stars should suffice our need. What we did is more like googling for “docker mysql” in
some sense. Anyways as for the next task, let’s pull it and go toward running run it.

Docker pull
We could directly run the image with the docker run command but in this tutorial, we are learning the docker commands so let’s
understand what docker pull can do for us. Docker pull command will pull an image or a repository from a registry.
A registry is a place that stores built docker images, DockerHub being the main one but as per the need you/your company can set up a
private docker image registry too. AWS also has a public container registry we can use.
To pull a docker image it would be best to know the specific version to pull, in our case we can visit the MySQL’s DockerHub tags page.
For this example, I will pull MySQL 8.0-oracle:

docker pull mysql:8.0-oracle

It will show an output like the below:


8.0-oracle: Pulling from library/mysql
2d35f3f87cf6: Pull complete
e08c104e7e4b: Pull complete
9a34eb48fc75: Pull complete
5bb6dedbc752: Pull complete
19a4f2fda7b8: Pull complete
dff080c7a5fa: Pull complete
5c984e7fd2f6: Pull complete
57b567fb3d57: Pull complete
bbbd9d96c94e: Pull complete
71907ccd70c5: Pull complete
Digest: sha256:fc7cc18cbd47405471f57a6cf3ae44883fc3aecff8248c5318f18e1bbbf4c7d3
Status: Downloaded newer image for mysql:8.0-oracle
docker.io/library/mysql:8.0-oracle
If there is a push there is a docker push command too but we will not learn about that in this post. Let’s see if it is pulled correctly
with docker images next.

Docker images
The docker command docker images lists images on the local system. It will list the images pulled in from repositories or built locally. As
we have pulled in the mysql8.0-oracle image we can see it listed with:

docker images

It will give us the following output:


ALIK SARKAR
018

REPOSITORY TAG IMAGE ID CREATED SIZE


mysql 8.0-oracle a1eb4ca73814 10 days ago 505MB

Depending on other images pulled or built locally you may see more images on your system.
One useful command to remove intermediate images or images that were not successfully built or pulled is below:

docker rmi -f $(docker images -f "dangling=true" -q)

This uses the docker rmi command used to remove images with docker images that are dangling, meaning they were not pulled or built
successfully. The above command is similar to docker image prune -a . You can read more aout docker image prune on it's official docs. It
is simpler and platform agnostic.
Now, as we know the image is pulled and available locally we can run the MySQL image in the subsequent section.

Docker run
The docker run command is used to run an image as a new container. To say that it has some parameters will be an understatement as we
can see lots of parameters with docker run –help .
Docker run is one of the most important docker commands to learn. It has multiple arguments to do many things. It would be
wise to understand the difference of image and container first.
If you are confused about Image and container, please read this post about Image vs container. In summary, an image is a snapshot of a
container and when an image runs (becomes a running instance) it is a container. Containers can be directly run with just a docker
run command without a docker pull. With the run command, Docker will pull the image and run it.
For this guide, we will use some of the main ones that are useful to run MySQL in our case, before running the command below please
execute mkdir /tmp/mysql-data , then run:

docker run --name mysql8 --rm -v /tmp/mysql-data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=KTQJbtWYtM1u1UUj -e


MYSQL_DATABASE=testing -p 3306:3306 -it mysql:8.0-oracle

So, what are the parameters we used for the docker run command, let’s elaborate on the parameters:

• --name is passed to name the container as mysql8 , if not passed docker will use a random name
• --rm is used to remove the container when it is stopped
• -v /tmp/mysql-data:/var/lib/mysql is added as volume to retain the data when the container restarts, it will vanish when the
host machine restarts as it is in /tmp. Volumes can be managed implicitly by Docker too.
• -e MYSQL_ROOT_PASSWORD=KTQJbtWYtM1u1UUj -e MYSQL_DATABASE=testing as utilized to set the root user’s
password and initializing a database named testing
• -p 3306:3306 maps host port 3306 to container port 3306, the port 3306 is MySQL’s default port. You can map to a different
host port too like 3307:3306 will map local post 3307 to container port 3306
• -it mysql:8.0-oracle - -it will show all logs as the tty is allocated and we are using the official MySQL image version 8.0 which
will run the Oracle flavor.

If we wanted to push the output to the background we can use the -d flag to keep the output detached and not show in the foreground. For
more options please skim through the official docker run docs.
Let’s understand what the above command does then we will also see what it outputs.

2022-05-14 06:13:34+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.29-1.el8 started.
2022-05-14 06:13:34+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2022-05-14 06:13:34+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.29-1.el8 started.
2022-05-14 06:13:34+00:00 [Note] [Entrypoint]: Initializing database files
2022-05-14T06:13:34.963954Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.29) initializing of server in progress as process
44
2022-05-14T06:13:34.974569Z 0 [Warning] [MY-010159] [Server] Setting lower_case_table_names=2 because file system for /var/lib/mysql/ is
case insensitive
2022-05-14T06:13:34.991554Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-05-14T06:13:39.989090Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-05-14T06:13:42.519457Z 6 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider
switching off the --initialize-insecure option.
ALIK SARKAR
018
2022-05-14 06:13:48+00:00 [Note] [Entrypoint]: Database files initialized
2022-05-14 06:13:48+00:00 [Note] [Entrypoint]: Starting temporary server
mysqld will log errors to /var/lib/mysql/46a76c820507.err
mysqld is running as pid 95
2022-05-14 06:13:50+00:00 [Note] [Entrypoint]: Temporary server started.
'/var/lib/mysql/mysql.sock' -> '/var/run/mysqld/mysqld.sock'
Warning: Unable to load '/usr/share/zoneinfo/iso3166.tab' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/leapseconds' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/tzdata.zi' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/zone.tab' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/zone1970.tab' as time zone. Skipping it.
2022-05-14 06:13:53+00:00 [Note] [Entrypoint]: Creating database testing

2022-05-14 06:13:53+00:00 [Note] [Entrypoint]: Stopping temporary server


2022-05-14 06:13:55+00:00 [Note] [Entrypoint]: Temporary server stopped

2022-05-14 06:13:55+00:00 [Note] [Entrypoint]: MySQL init process done. Ready for start up.

2022-05-14T06:13:56.134193Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.29) starting as process 1


2022-05-14T06:13:56.142565Z 0 [Warning] [MY-010159] [Server] Setting lower_case_table_names=2 because file system for /var/lib/mysql/ is
case insensitive
2022-05-14T06:13:56.154825Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-05-14T06:13:57.163042Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-05-14T06:13:57.725555Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2022-05-14T06:13:57.725586Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are
now supported for this channel.
2022-05-14T06:13:57.814829Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket:
/var/run/mysqld/mysqlx.sock
2022-05-14T06:13:57.814890Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.29' socket:
'/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server - GPL.

Basically, our MySQL server is running right now and able to accept any connections.
I have written another post for running MySQL with docker-compose, you can read it as well. There are other posts related to Docker as
well like running Postgres with Docker, Node.js and Docker, Redis on Docker and RabbitMQ with Docker.
Now to check if the container is running or not we can use the docker ps command which we will discuss next.

Docker ps
The docker ps command is used to list containers. It will list all running containers and with a -a flag it will list all containers,s not just
the running one. If you try docker ps you should be able to see something like the below:

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES


46a76c820507 mysql:8.0-oracle "docker-entrypoint.s…" 2 minutes ago Up 2 minutes 0.0.0.0:3306->3306/tcp, 33060/tcp mysql8

At this point, we have listed our running container and can verify that it is mapping to local post 3306 and has the name we gave it
of mysql8 . In the consequent section, we will go into the running container and execute some commands.

Docker exec
The docker exec command is useful to run a command in a running container. Depending on what is available in the container we can go
into the container with sh/bash and run other commands inside the running container.
For our example, as we have a running MySQL container let’s make sure that our testing database exists with the following series of
commands:

docker exec -it mysql8 /bin/bash


#once we are inside the container, we can run
mysql -uroot -p
#type/paste the password, and once we gave the MySQL CLI running, we can execute
show databases;

This will look similar to the following:


ALIK SARKAR
018

As seen, docker exec is another very useful command to go inside a docker container or just run one-off commands on a running
container. It is very helpful to debug any issues in a running container by executing extra commands or checking logs inside the
container. In the subsequent sections, we will explore docker logs to see the logs of the running container.

Docker logs
The docker logs command is used to fetch the logs of a container. It also has multiple parameters of which the -f to follow the logs is one
of the most useful ones. It can be used as follows:

docker logs -f mysql8

Which will render an output like the below:

2022-05-14 11:37:39+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.29-1.el8 started.
2022-05-14 11:37:39+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2022-05-14 11:37:39+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.29-1.el8 started.
2022-05-14 11:37:39+00:00 [Note] [Entrypoint]: Initializing database files
2022-05-14T11:37:39.274964Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.29) initializing of server in progress as process
44
2022-05-14T11:37:39.281699Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-05-14T11:37:39.382089Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-05-14T11:37:39.772787Z 6 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider
switching off the --initialize-insecure option.
2022-05-14 11:37:41+00:00 [Note] [Entrypoint]: Database files initialized
2022-05-14 11:37:41+00:00 [Note] [Entrypoint]: Starting temporary server
mysqld will log errors to /var/lib/mysql/1e296cc4efac.err
mysqld is running as pid 95
2022-05-14 11:37:41+00:00 [Note] [Entrypoint]: Temporary server started.
'/var/lib/mysql/mysql.sock' -> '/var/run/mysqld/mysqld.sock'
Warning: Unable to load '/usr/share/zoneinfo/iso3166.tab' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/leapseconds' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/tzdata.zi' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/zone.tab' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/zone1970.tab' as time zone. Skipping it.
2022-05-14 11:37:43+00:00 [Note] [Entrypoint]: Creating database testing

2022-05-14 11:37:43+00:00 [Note] [Entrypoint]: Stopping temporary server


ALIK SARKAR
018
2022-05-14 11:37:44+00:00 [Note] [Entrypoint]: Temporary server stopped

2022-05-14 11:37:44+00:00 [Note] [Entrypoint]: MySQL init process done. Ready for start up.

2022-05-14T11:37:44.586231Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.29) starting as process 1


2022-05-14T11:37:44.589830Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-05-14T11:37:44.631698Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-05-14T11:37:44.709052Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2022-05-14T11:37:44.709084Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are
now supported for this channel.
2022-05-14T11:37:44.718522Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.29' socket:
'/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server - GPL.
2022-05-14T11:37:44.718526Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket:
/var/run/mysqld/mysqlx.sock

This command is very useful when our container is running in detached mode to view its logs. The docker logs command comes in very
handy for webservers or application servers where logs are piped to the stdout and gives us valuable insight into the running application.
Next up we will stop and kill our running container.

Docker stop
The docker stop command is used to stop one or more running containers. We will use this command to stop our mysql8 container. We
can pass the -t flag to wait for the container to stop for given number of seconds like:

docker stop -t 5 mysql8

If the -t 5 parameter is not passed, the docker stop command will wait for 10 seconds by default. It will output the name of the container.
A container can also be stopped by passing the container id not only the name. After the container is stopped if we do a docker ps we will
not see our mysql8 container running anymore.
So you have docker kill too?

Docker kill
Similar to docker stop, there is the docker kill command that is used to kill one or more running containers. We can kill the running
container named mysql8 with:

docker kill mysql8

This command will kill the container. You might be wondering what is the difference between stop and kill then right? That will be
answered next:
Difference between docker stop and kill
The difference between docker stop and docker kill is that docker stop issues a SIGTERM so waits for the container to clean up before
killing it. Whereas docker kill will issue a SIGKILL which will not be as polite and directly kill the container. To know other minute
differences between the two, follow this post.

Docker cp
The docker cp is a handy command but a lesser-known one. It is used to copy files/folders between a container and the host’s local file
system. One use-case I have used recently is to copy the node_modules from the container in the build phase in the CI pipeline and reuse
it in the test phase on the host. It easily saved 30+ seconds of npm install time. Below are a couple of examples to copy a file from host to
container and vice versa.
Copy file from host to the container
Let’s say we want to copy a SQL file called test.sql into the running MySQL container named mysql8, we can do it with:

docker cp ./test.sql mysql8:/tmp

To verify the file is there we can execute:


ALIK SARKAR
018

docker exec -it mysql8 ls -al /tmp

It will show something like the below:

total 12
drwxrwxrwt 1 root root 4096 May 14 12:14 .
drwxr-xr-x 1 root root 4096 May 14 12:14 ..
-rw-r--r-- 1 501 games 19 May 14 12:13 test.sql

Copy file from container to host


Now we will try to copy the same file from the container to the host with a different filename by executing:

docker cp mysql8:/tmp/test.sql ./test2.sql

If we do a ls -al | grep test2 on that folder in the host we will see the file has been copied from the container to the host folder. The docker
cp command can be useful to copy a file from or to the container on the fly without the need to rebuild the image again.
In addition to the above 10+ command, there are many other useful docker commands. Some of these are listed in the next part.

You might also like