Devops Q&A
Devops Q&A
018
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.
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.
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.
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.
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.
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.
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 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
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 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
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.
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.
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.
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.
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.
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.
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.
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.
• 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.
• 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.
7. mkdir command
Use mkdir command to make a new directory — if you type mkdir Music it will create a directory called Music.
• 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.
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.
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.
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.
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.
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.
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.
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.
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 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.
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.
jobs command will display all current jobs along with their statuses. A job is basically a process that is started by
the shell.
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:
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.
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.
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.
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.
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.
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
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.
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.
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]”
This command sets the author name and email address respectively to be used with your commits.
git init
Usage: git init [repository name]
git clone
Usage: git clone [url]
This command is used to obtain a repository from an existing URL.
git add
Usage: git add [file]
git commit
Usage: git commit -m “[ Type in the commit message]”
This command records or snapshots the file permanently in the version history.
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.
This command shows the differences between the files in the staging area and the latest version present.
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
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
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
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]
git branch
Usage: git branch
This command lists all the local branches in the current repository.
git checkout
Usage: git checkout [branch name]
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.
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
Centralized Version Control is a version control system using server/client model and server contains all the
history of source code.
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.
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.
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.
• The distributed version control tool is used for source code management
Features of Git
• Tracks history
• Creates backups
• Scalable
• Supports collaboration
• Branching is easier
• Distributed development
Git Workflow
• 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.
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:
For example, changes made in code base among developers include version control system for tracking changes
with specific lines.
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.
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
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.
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.
• 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
• Chef Workstation
• The workstation is used to interact with Chef-server and also to interact with Chef-nodes.
• 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.
• 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.
• 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.
• 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.
• Ohai is used for determining the system state at beginning of Chef run in Chef-Client. It Collects. All the
system configuration data.
• 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.
• 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.
• 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:
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:
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:
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
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
An attribute is a specific detail about a node. Attributes are used by Chef Infra Client to understand:
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:
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
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.
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
<scope>compile</scope>
</dependency>
</dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
<version>1.4.4</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
ALIK SARKAR
018
</dependency>
<dependency>
<groupId>extDependency</groupId>
<artifactId>extDependency</artifactId>
<scope>system</scope>
<version>1.0</version>
<systemPath>${basedir}\war\WEB-INF\lib\extDependency.jar</systemPath>
</dependency>
<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>
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.
• 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.
• 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.
• 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 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
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:
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:
Here, we are asking docker to give us only the official images and limit it to 5 for mysql. It will yield something like:
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 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
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:
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:
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:55+00:00 [Note] [Entrypoint]: MySQL init process done. Ready for start up.
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:
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:
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:
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:44+00:00 [Note] [Entrypoint]: MySQL init process done. Ready for start up.
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:
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:
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:
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
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.