<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Vinod Manral on Medium]]></title>
        <description><![CDATA[Stories by Vinod Manral on Medium]]></description>
        <link>https://medium.com/@vndmanral1?source=rss-3602b52ef054------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*83qjU8aWqcm9zfXI.jpg</url>
            <title>Stories by Vinod Manral on Medium</title>
            <link>https://medium.com/@vndmanral1?source=rss-3602b52ef054------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 09:43:59 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@vndmanral1/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Complete Gitlab Interview Question Answers]]></title>
            <link>https://medium.com/@vndmanral1/complete-gitlab-interview-question-answers-b0a2fd0a4c15?source=rss-3602b52ef054------2</link>
            <guid isPermaLink="false">https://medium.com/p/b0a2fd0a4c15</guid>
            <category><![CDATA[gitlab-interview-question]]></category>
            <dc:creator><![CDATA[Vinod Manral]]></dc:creator>
            <pubDate>Wed, 22 Jan 2025 06:40:24 GMT</pubDate>
            <atom:updated>2025-01-22T06:40:24.733Z</atom:updated>
            <content:encoded><![CDATA[<h3>Q1. How is GitLab different from GitHub?</h3><p>The major difference between GitHub and GitLab is the platform each philosophy presents. GitHub has higher availability and is more focused on infrastructure performance, while GitLab is more focused on offering a features-based system with a centralized, integrated platform for web developers.</p><h3>Q2. Why GitLab is better than Jenkins?</h3><p>GitLab provides more than what Jenkins is hoping to evolve to, by providing a fully integrated single application for the entire DevOps lifecycle. More than Jenkins’ goals, GitLab also provides planning, SCM, packaging, release, configuration, and monitoring (in addition to the CI/CD that Jenkins is focused on).</p><h3>Q3. Is GitLab better than Jira?</h3><p>While Jira is better for mid-sized teams who need specific things to test and track while developing code, GitLab is ideal for the largest teams out there who need features to improve their workflow.</p><h3>Q4. Is GitLab better than bitbucket?</h3><p>Summary. Atlassian Bitbucket gives teams Git code management, but also one place to plan projects, collaborate on code, test, and deploy. … <strong>GitLab</strong> is a complete DevOps platform, delivered as a single application, with built-in project management, source code management, CI/CD, monitoring and more.</p><h3>Q5. Why should I use GitLab?</h3><p>Why Use GitLab? The main benefit of using GitLab is that it allows all the team members to collaborate in every phase of the project. GitLab offers tracking from planning to creation to help developers automate the entire DevOps lifecycle and achieve the best possible results.</p><h3>Q6. What is the pipeline in GitLab?</h3><p>A pipeline is a group of jobs that get executed in stages. All of the jobs in a stage are executed in parallel (if there are enough concurrent Runners), and if they all succeed, the pipeline moves on to the next stage. If one of the jobs fails, the next stage is not (usually) executed.</p><h3>Q7. Is GitLab free for commercial use?</h3><p>Historically, GitLab was provided as two different software distributions, each with its own separate source code repository and documentation: Community Edition (CE) and Enterprise Edition (EE). … Enterprise Edition can be downloaded, installed, and run without a commercial subscription.</p><h3>Q8. What is the difference between fork and branch in GitLab?</h3><p>Forking creates a full copy of your repository, whereas branching only adds a branch to your existing tree. The file size of the branch can vary depending on the branch that you are on. Under the hood git readily accesses the different files and commits depending on what branch you are using.</p><h3>Q9. What is Project slug in GitLab?</h3><p>A repository slug is a URL-friendly version of a repository name, automatically generated by Bitbucket for use in the URL. For example, if your repository name was ‘føøbar’, in the URL it would become ‘foobar’.</p><h3>Q10. Does GitLab have a GUI?</h3><p>But unlike Github, Gitlab does not have a Git GUI client of its own. A Git GUI client is the program that you install on your computer, that lets you control the workflow of your repository with graphical tools.</p><h4>Q11. What is GitLab used for?</h4><p>GitLab is a web-based Git repository manager with wiki and issue tracking features.</p><h4>Q12. Can you explain what a CI/CD pipeline is in the context of software development and deployment?</h4><p>A CI/CD pipeline is a set of automated processes that allow for the continuous integration and continuous delivery of software. This means that new code changes can be automatically integrated into the main codebase and then automatically deployed to a staging or production environment. This can help to speed up the software development and deployment process, and can also help to ensure that new code changes do not introduce any new bugs or errors.</p><h4>Q13. How does GitLab help achieve continuous integration and delivery?</h4><p>GitLab provides a platform for developers to collaborate on code projects, with built-in tools to help manage the software development lifecycle. This includes features for managing code changes, testing and deploying code, and tracking issues. By providing these tools in a single platform, GitLab helps teams to more easily achieve continuous integration and delivery.</p><h4>Q14. What are some common features of GitLab?</h4><p>Some common features of GitLab include being able to create projects, track issues, and collaborate with other users. GitLab also has a built-in continuous integration and delivery pipeline, making it easy to deploy your code.</p><h4>Q15. What are the main components of GitLab?</h4><p>The main components of GitLab are the GitLab web interface, the GitLab API, the GitLab CI/CD pipelines, and the GitLab Runner. The web interface is the primary way that users interact with GitLab, and it provides a way to view and manage repositories, issues, merge requests, and more. The GitLab API provides a way for developers to access and manipulate data within GitLab, and the GitLab CI/CD pipelines allow for automated testing, building, and deployment of code. The GitLab Runner is a tool that runs jobs and provides feedback to GitLab.</p><h4>Q16. What are some major differences between GitLab and GitHub?</h4><p>Some major differences between GitLab and GitHub include the fact that GitLab is open source and self-hosted, while GitHub is proprietary and hosted by GitHub. Additionally, GitLab has a built-in continuous integration and delivery tool, while GitHub does not. Finally, GitLab offers unlimited private repositories for free, while GitHub charges for private repositories.</p><h4>Q17. What is the difference between GitLab Community Edition (CE) and Enterprise Edition (EE)?</h4><p>GitLab Community Edition is the free and open source version of GitLab, while GitLab Enterprise Edition is the paid, premium version. GitLab Enterprise Edition includes additional features and support not found in the Community Edition, such as LDAP/AD integration, Geo nodes, and multiple project templates.</p><h4>Q18. How would you define an issue tracker in the context of software development projects?</h4><p>An issue tracker is a software application that helps developers manage the tasks and issues associated with a software development project. It is typically used to track bugs, feature requests, and other work items. Issue trackers can be used to track work items for individual developers or for teams of developers working on a project.</p><h4>Q19. Is it possible to use GitLab without using source code management services like Git or Mercurial?</h4><p>No, GitLab requires the use of either Git or Mercurial for source code management in order to function properly.</p><h4>Q20. What’s the best way to keep track of issues that need attention across multiple users on your team?</h4><p>One way to keep track of issues that need attention across multiple users on your team is to use the GitLab issue tracker. This will allow you to assign issues to specific users, set deadlines, and add labels to help organize and prioritize your issues.</p><h4>Q21. What is SourceForge and how does it relate to GitLab?</h4><p>SourceForge is a web-based service that offers software developers a centralized place to control and manage free and open source software development. GitLab is a web-based Git repository manager with wiki and issue tracking features. SourceForge offers GitLab as a service to open source projects.</p><h4>Q22. What do you understand about the term “hosted service” as it applies to SaaS platforms like GitLab?</h4><p>A hosted service is a type of subscription-based service where the provider manages the infrastructure and security for the customer. This type of service is often used for mission-critical applications where the customer does not want to be responsible for managing the underlying infrastructure.</p><h4>Q23. What is the main benefit of using a hosted service platform like GitLab over setting up your own server and installing</h4><p>The main benefit of using a hosted service like GitLab is that it is much easier to set up and maintain. With GitLab, you don’t have to worry about installing and configuring the software, which can be a complex and time-consuming process. Additionally, hosted platforms typically offer more features and integrations than self-hosted solutions.</p><h4>Q24. the open-source version of GitLab?</h4><p>GitLab is an open-source project that provides a web-based interface for managing Git repositories. It is similar to GitHub, but also includes features for project management, issue tracking, and continuous integration.</p><h4>Q25. What are milestones and how can they be used to organize issues in GitLab?</h4><p>Milestones are a way to group issues together in GitLab. You can use them to track progress on a project, or to organize issues by release. To create a milestone, go to the Issues tab of your project and click on the Milestones link. From there, you can create a new milestone and add issues to it.</p><h4>Q26. What is GitLab Auto DevOps? Why should I use it?</h4><p>GitLab Auto DevOps is a feature that can be enabled on GitLab projects to automatically run a set of pre-configured tasks whenever code is pushed to the project repository. These tasks can include things like running tests, building and deploying code, and more. Auto DevOps can save time and effort by automating these tasks, and it can also help to ensure that projects are always up-to-date and compliant with best practices.</p><h4>Q27. What is a Wiki page and why is it useful?</h4><p>A Wiki page is a page that can be edited by anyone who has access to the GitLab project. This makes it a useful tool for collaboration, as it allows users to easily share information and make changes as needed.</p><h4>Q28. What are some security concerns with GitLab?</h4><p>One of the main security concerns with GitLab is that it is a single point of failure for your git repository. If GitLab were to go down, then you would not be able to access your code. Additionally, GitLab is a hosted service, which means that you are trusting them with your code. Another security concern is that GitLab does not offer two-factor authentication, which means that your account could be compromised if your password is guessed or stolen.</p><h4>Q29. What is the difference between a project, group, and subgroup in the context of GitLab?</h4><p>A project is a collection of code repositories and issues related to a specific topic or goal. A group is a collection of projects and subgroups, and is used to organize projects in a logical way. A subgroup is a collection of projects that is nested within a group.</p><h4>Q30. Is there any limit on the number of projects that can be created in GitLab?</h4><p>No, there is no limit on the number of projects that can be created in GitLab.</p><h4>Q31. What is the biggest concern when managing large numbers of repositories in GitLab?</h4><p>One of the main concerns when managing large numbers of repositories in GitLab is the potential for repository sprawl. This can happen when users create too many repositories, or when repositories are not properly maintained and end up being abandoned. Repository sprawl can lead to problems with performance and organization, so it is important to keep it under control.</p><h3>Q32.What are the minimum systems Requirements?</h3><ul><li>GitLab Control requires at least iOS 8.1 on the iPhone, iPod Touch, iPad and iPad Mini.</li><li>It currently supports GitLab server version 9.x and higher, but it is highly optimized for GitLab 10.x.</li><li>Please note that some of the features may not be available or not work at all on versions prior to 9.0.</li></ul><p><strong>Q33.Where are my Git Data Stored? How secure is it?</strong></p><p>GitLab Control stores your data both online (on your host) and locally. We use the device keychain to store your credentials and an encrypted database to store all the others data. Every message transferred is encrypted with TLS/SSL only when the appropriate option is enabled both on the app and on your GitLab instance.</p><p><strong>Q34.How do you revert a commit that had already been pushed and made public?</strong></p><p>One or more commits can be reverted with the use of <em>git revert</em>. This command, in essence, creates a new commit with patches that cancel out the changes introduced in specific commits. In case the commit that needs to be reverted has already been published or changing the repository history is not an option, <em>git revert</em> can be used to revert commits. Running the following command will revert the last two commits:</p><pre>git revert HEAD~2..HEAD</pre><p>Alternatively, one can always checkout the state of a particular commit from the past, and commit it a new.</p><p><strong>Is Gitlab The Only Git Repository That I Can Use At Sealed Air?</strong></p><p>Whilst there is nothing stopping you running Git only on your local machine to track changes, you will really start to see benefits by using GitLab and getting others involved in your projects. It is built for sharing and working together on code and text.</p><p><strong>When Should I Consider Gitlab?</strong></p><p>Version control software, like Git, allows you to have “versions” of a project, which show the changes that were made to code, or text files, over time, and allows you to backtrack if necessary and undo those changes or merge your code with others, line by line.</p><p><strong>Should I Be Concerned With Confidential Or Proprietary Solutions In Gitlab?</strong></p><p>GitLab is ideal at storing source code for projects; however, confidential information such as passwords and credentials should not be stored in git. With regards to hosting our code, there should be no issue with the hosting of code that is either open license (MIT, GPL, and BSD), we have created or licensed for us to use, however, code that has a license for limited use should be handled carefully. If you are not sure, please contact Risk Management or Legal teams.</p><p><strong>What Is The Cost Per User Or Project?</strong></p><p>GitLab is an Open Source software application under MIT license running on our private and secure instance. There is no cost to add users to GitLab.</p><p><strong>What Happens When Active Gitlab Users Are Terminated?</strong></p><p>We have implemented Single Sign-On (SSO) for GitLab. This means that terminated users will not be able to access GitLab.</p><p><strong>How do you squash last N commits into a single commit</strong>?</p><p>Squashing multiple commits into a single commit will overwrite history, and should be done with caution. However, this is useful when working in feature branches. To squash the last N commits of the current branch, run the following command (with {N} replaced with the number of commits that you want to squash):</p><pre>git rebase -i HEAD~{N}</pre><p>Upon running this command, an editor will open with a list of these N commit messages, one per line. Each of these lines will begin with the word “pick”. Replacing “pick” with “squash” or “s” will tell Git to combine the commit with the commit before it. To combine all N commits into one, set every commit in the list to be squash except the first one. Upon exiting the editor, and if no conflict arises, <em>git rebase</em> will allow you to create a new commit message for the new combined commit.</p><p><strong>How do you setup a script to run every time a repository receives new commits through push?</strong></p><p>To configure a script to run every time a repository receives new commits through push, one needs to define either a pre-receive, update, or a post-receive hook depending on when exactly the script needs to be triggered.</p><p>Pre-receive hook in the destination repository is invoked when commits are pushed to it. Any script bound to this hook will be executed before any references are updated. This is a useful hook to run scripts that help enforce development policies.</p><p>Update hook works in a similar manner to pre-receive hook, and is also triggered before any updates are actually made. However, the update hook is called once for every commit that has been pushed to the destination repository.</p><p>Finally, post-receive hook in the repository is invoked after the updates have been accepted into the destination repository. This is an ideal place to configure simple deployment scripts, invoke some continuous integration systems, dispatch notification emails to repository maintainers, etc.</p><p>Hooks are local to every Git repository and are not versioned. Scripts can either be created within the hooks directory inside the “.git” directory, or they can be created elsewhere and links to those scripts can be placed within the directory.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b0a2fd0a4c15" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Ultimate DevOps Interview Questions & Answers  list]]]></title>
            <link>https://medium.com/@vndmanral1/ultimate-devops-interview-questions-answers-list-5927ce619590?source=rss-3602b52ef054------2</link>
            <guid isPermaLink="false">https://medium.com/p/5927ce619590</guid>
            <dc:creator><![CDATA[Vinod Manral]]></dc:creator>
            <pubDate>Mon, 19 Dec 2022 05:02:36 GMT</pubDate>
            <atom:updated>2025-09-22T14:23:08.504Z</atom:updated>
            <content:encoded><![CDATA[<h3>Ultimate DevOps Interview Questions &amp; Answers list</h3><h3>Top 30+ DevOps Interview Questions [Ultimate list]</h3><p>DevOps — a renowned software development practice that many companies adopt into their workflow — has been drawing a great deal of attention lately. More and more companies have implemented this approach, including large enterprises such as Netflix, Facebook, and Amazon. As a matter of fact, DevOps-related jobs have become one of the most promising career choices for IT professionals today.</p><p>You might be among the developers who are planning to advance your career as a DevOps engineer, analyst, or specialist. Besides the required technical skills, a DevOps job interview can be tough without diligent preparation.</p><p>This blog post presents more than 30 of the most common DevOps interview questions, neatly broken out into themes, so you can ace your next interview and successfully get that dream job.</p><h3>DevOps Terms and Definitions</h3><ol><li><strong>What is DevOps?</strong></li></ol><p>In general, DevOps is the gray area between development (Dev) and operations (Ops) teams in a product development process. DevOps is a culture in which communication, integration, and collaboration in the product development cycle are emphasized. Thus, it eliminates the silos between software development and operations teams, allowing them to focus on rapid and continuous product deployment.</p><p><strong>2. What is continuous integration?</strong></p><p>Continuous integration (CI) is the process of automatically integrating code changes from multiple developers into a shared repository. Automated tests are utilized to verify and affirm the additional codes generate no conflict with the existing codebase. Ideally, code changes should be merged multiple times a day, at every commit, with the help of CI tools.</p><p><strong>3. What is continuous delivery?</strong></p><p>Continuous delivery (CD), together with CI makes a complete flow for deliverable code packages. In this phase, automated building tools are applied to compile artifacts (e.g., source code, test scripts, configuration files, and environments) and have them ready to be delivered to the end user. With that in mind, in a CD environment, new releases are just one click away from being published with fully functional features and minimal human intervention.</p><p>For more details, please refer to our <a href="https://www.katalon.com/resources-center/blog/ci-cd-introduction/">introduction to CI/CD article</a>.</p><p><strong>4. What is continuous deployment?</strong></p><p>Continuous deployment takes CD to the next level by having new changes in code integrated and delivered automatically into the release branch. More specifically, as soon as the updates pass all stages of the production pipeline, they are deployed directly to the end-user without human intervention. Thus, to successfully utilize continuous deployment, the software artifacts must go through rigorously established automated tests and tools before being deployed into the production environment.</p><p><strong>5. What is continuous testing and its benefits?</strong></p><p>Continuous testing is the practice of applying automated tests early, gradually, and adequately in the software delivery pipeline. In a typical CI/CD workflow, builds are released in small batches. Therefore, it is impractical to manually perform test cases for each delivery. Automated continuous testing eliminates the manual steps and turns them into automated routines, which reduces human effort. That’s why automated continuous testing is essential for the DevOps culture.</p><p>Benefits of continuous testing:</p><ul><li>Ensures the quality and speed of builds</li><li>Enables faster software delivery and a continuous feedback mechanism</li><li>Detects errors as soon as they occur in the system</li><li>Reduces business risks and evaluates potential problems before they become real problems</li></ul><p><strong>6. What is version control and its uses?</strong></p><p>Version control (or source control) is a repository in which all changes in the source code are stored and managed at all times. Version control provides an operating history of code development that allows developers to rewind if they made any mistakes, compare versions, and finalize the best version of the code. All the code versions must be updated and checked into the version control, making it the single source of truth that is applicable for all environments.</p><p><strong>7. What is Git?</strong></p><p>Git is a distributed version control system that tracks changes in the code repository. Utilizing GitHub flow, Git revolves around a branch-based workflow that streamlines team collaboration as their projects progress over time.</p><h3>Reasons for Implementing DevOps</h3><ol><li><strong>Why does DevOps matter? How does DevOps benefit teams in software delivery?</strong></li></ol><p>In today’s digitized world, organizations must reinvent their product deployment systems to be more robust and flexible in order to keep up with the competition.</p><p>This is where the DevOps concept comes into the picture. DevOps plays a crucial part in generating mobility and agility to the entire software development pipeline, from idea to deployment and to the end-users. DevOps is the solution that drives a more streamlined and efficient process of continuously updating and improving products.</p><p><strong>2. Explain how DevOps is helpful for developers.</strong></p><p>In a world without DevOps, the workflow would start with developers building new codes, shipping, and integrating them, and then it’s the operation team’s duty to package and deploy the codes. After that, they have to wait for feedback. And if things go wrong, they have to go back and do it all over again to solve the bugs. In this process, there is exorbitant manual communication between different teams involved in the project.</p><p>Applying DevOps reduces developer tasks to building code only, as CI/CD practices consolidate and automate the remaining tasks. Combining the engineering and operation teams helps to create better communication and collaboration as processes become more transparent and accessible by all team members.</p><p><strong>3. Why has DevOps gained popularity in software delivery recently?</strong></p><p>DevOps has gained attention over the last few years primarily due to its ability to streamline the development, testing, and deployment processes for organizational operations and convert them into business value.</p><p>Technology is developing at a fast pace. Hence, organizations must adopt a new workflow — the DevOps and Agile approach — to streamline and stimulate their operations to stay ahead of the competition. DevOps’ features and benefits are reflected clearly through the successful application of the continuous deployment approach at both Facebook and Netflix, which boosted their growth without disrupting their ongoing operations.</p><p><strong>4. What are the benefits of CI/CD?</strong></p><p>The combination of CI and CD unifies all code changes into one single repository and runs them through automated tests, thus fully developing the product throughout all phases and making it ready for deployment at all times.</p><p>CI/CD enables organizations to roll out product updates as quickly, efficiently, and automatically as their customers expect them to be.</p><p>In short, a well-planned and well-executed CI/CD pipeline accelerates release rates and reliability and mitigates the code changes and defects of your product, resulting in much higher customer satisfaction.</p><p><strong>5. What are some benefits of continuous delivery?</strong></p><p>Manually releasing changes in code gives teams complete control of the product. In some cases, a new product release aligns with a bigger picture in the organization, for example, a promotion strategy with clear business purposes.</p><p>By automating repetitive and mundane tasks, IT professionals have more time to focus on improving the product without worrying about the integration progress.</p><p><strong>6. What are some benefits of continuous deployment?</strong></p><p>With continuous deployment, developers can focus solely on the product because their final task in the pipeline is to review pull requests and merge them to the master branch. This method enables frictionless deployment and shortens the deployment duration by releasing new features and fixes right after they have passed the automated tests.</p><p>Customers are the ones to evaluate the quality of each release. Bug fixes for new releases are easier to handle because each release is delivered in small batches.</p><h3>How to Effectively Implement DevOps</h3><ol><li><strong>Define a typical DevOps workflow.</strong></li></ol><p>A typical DevOps workflow can be organized into four stages:</p><ul><li><strong>Version control — </strong>This is the stage in which the source code is stored and managed. The version control contains different versions of the code.</li><li><strong>Continuous integration </strong>— In this step, developers start to build components and have them compiled, validated, and tested with code review, unit testing, and integration testing.</li><li><strong>Continuous delivery </strong>— This is the next level of continuous integration, in which the release and testing processes are fully automated. CD ensures new releases are delivered quickly and sustainably to the end users.</li><li><strong>Continuous deployment </strong>— After the application has successfully passed all testing requirements, it is automatically deployed on the production server for release without any human intervention.</li></ul><p>To learn more, read <a href="https://www.katalon.com/resources-center/blog/devops-implementation-strategy/">From DevOops to DevOps | Best Strategies to Implement for Your Team</a>.</p><p><strong>2. What are the core operations of DevOps?</strong></p><p>The core operations of DevOps in terms of development and infrastructure are:</p><ul><li><strong>Software development</strong></li><li>Code building</li><li>Code coverage</li><li>Unit testing</li><li>Packaging</li><li>Deployment</li><li><strong>Infrastructure</strong></li><li>Provisioning</li><li>Configuration</li><li>Orchestration</li><li>Deployment</li></ul><p><strong>3. What are some precautions that teams need to consider before implementing DevOps?</strong></p><p>There are a few misconceptions about DevOps practices that could potentially lead to tragic failures when organizations try to apply this new approach:</p><ul><li>DevOps is more than simply applying new tools and/or forming a new “department” and expecting it to work. In fact, DevOps is considered a culture in which development and operations teams work side by side following a mutual framework.</li><li>Organizations do not need to define a clear vision for their DevOps practices. Applying DevOps initiatives is a notable change to both development and operation teams. Therefore, having a clear roadmap, goals, and expectations for integrating DevOps in your organization will eliminate confusion and provide clear guidelines from the start.</li><li>After the DevOps practices have been applied across the organization, the management team needs to establish and nurture a continuous learning and improvement culture. Failures and problems in the system should be treated as a valuable medium for teams to learn from mistakes and prevent those mistakes from recurring.</li></ul><p><strong>4. What role does the SCM team play in DevOps?</strong></p><p>Software configuration management (SCM) is the practice of tracking and keeping records of the development environment, including all the changes and adjustments made in the operating system.</p><p>In DevOps, SCM is built as codes under the umbrella of Infrastructure as Code practice.</p><p>SCM simplifies tasks for developers as they no longer have to manually manage the configuration processes. This process is now constructed in a machine-readable form and is automatically duplicated and standardized.</p><p><strong>5. What role does the Quality Assurance (QA) team play in DevOps?</strong></p><p>As DevOps practices become a more desired culture in innovative organizations, QA teams’ responsibilities and relevance have shown signs of decline in today’s automated world.</p><p>However, this can be considered a myth. The rise of DevOps is not equal to the end of QA roles. It only means that their working environment and required expertise are changing. Therefore, their main focus should be to professionally evolve in order to keep up with this maturing trend.</p><p>In DevOps, QA teams play a strategic role to ensure the stability of continuous delivery practices as well as perform the exploratory testing tasks that automated and repetitive tests cannot fulfill. Their insights in assessing the test and detecting the most valuable tests still play a crucial role in mitigating bugs in the last steps of a release.</p><p><strong>6. What are some tools used for DevOps? Describe your experience working with any of these tools.</strong></p><p>Throughout a typical DevOps lifecycle, there are various tools to support different phases of product development. The most common tools for DevOps can be divided into six key phases:</p><ul><li><strong>Continuous development:</strong> Git, SVN, Mercurial, CVS, Jira</li><li><strong>Continuous integration:</strong> Jenkins, Bamboo, Hudson</li><li><strong>Continuous delivery:</strong> Nexus, Archiva, Tomcat</li><li><strong>Continuous deployment:</strong> Puppet, Chef, Docker</li><li><strong>Continuous monitoring: </strong>Splunk, ELK Stack, Nagios</li><li><strong>Continuous testing:</strong> Selenium, Katalon Studio</li></ul><p><strong>7. How do you apply change management in DevOps practices?</strong></p><p>The typical change management approach needs to be appropriately integrated with DevOps’s modern practices. The first step is to centralize changes into a single platform to streamline the change, problem, and incident management processes.</p><p>Next, businesses should establish high transparency standards to make sure everyone is on the same page and assure accuracy over internal information and communication.</p><p>Stratifying the upcoming changes and establishing robust policies will help minimize risks and shorten the timeline for change. Lastly, organizations should apply automation into their process and integrate it with their DevOps software.</p><h3>How to Effectively Implement CI/CD</h3><p><strong>8. What are some core components of CI/CD?</strong></p><p>A stable CI/CD pipeline requires a repository management tool that acts as a version control system so that developers can keep track of changes in the software build.</p><p>In the version control system, developers can also collaborate on a project, compare between versions, and undo any mistakes they make, thus mitigating disruption to all team members.</p><p>Continuous testing and automated testing are the two most pivotal keys to successfully establishing a seamless CI/CD pipeline. Automated testing must be integrated into all product development phases (including unit, integration, and system testing) to cover all functionalities such as performance, usability, performance, load, stress, and security.</p><p><strong>9. What are some common practices of CI/CD?</strong></p><p>Here are some best practices for establishing an efficient CI/CD pipeline:</p><ul><li>Develop a DevOps culture</li><li>Implement and utilize continuous integration</li><li>Deploy to every environment the same way</li><li>Fail and restart your pipeline</li><li>Apply version control</li><li>Include the database in the pipeline</li><li>Monitor your continuous delivery pipeline</li><li>Get your CD pipeline flowing</li></ul><p><strong>10. When is the best time to implement CI/CD?</strong></p><p>The transition to DevOps requires a complete reshaping of your software development culture, including the workflow, organizational structure as well as infrastructure. Therefore, organizations must prepare themselves for a major change when implementing DevOps.</p><p><strong>11. What are some common CI/CD servers?</strong></p><ul><li>Visual Studio</li></ul><p>Visual Studio (VS) supports a fully developed DevOps system with agile planning, source code control, package management, testing and release automation, and continuous monitoring.</p><ul><li>TeamCity</li></ul><p>TeamCity is an intelligent CI server that offers framework support and code coverage without any extra plugin install needed and no mods to build scripts.</p><ul><li>Jenkins</li></ul><p>A self-contained CI server, it supports collaboration between development and operation teams with a shared pipeline and error tracking function. It can also be combined with hundreds of dashboard plugins.</p><ul><li>GitLab</li></ul><p>GitLab’s users can customize the platform for efficient continuous integration and deployment. GitLab helps CI/CD teams to accelerate in-code shipping, errors identity, and program recovery rollout.</p><ul><li>Bamboo</li></ul><p>Bamboo is a continuous integration server for product release management automation. Bamboo keeps track of all deployments on all tools and communicates errors in real-time.</p><p><strong>12. Describe an efficient workflow for continuous integration.</strong></p><p>A successful workflow when implementing continuous integration encompasses the following practices:</p><ul><li>Implement and maintain a repository for the project’s source code</li><li>Automate the build and integration</li><li>Make the build self-testing</li><li>Commit changes daily to the baseline</li><li>Build all commits added to the baseline</li><li>Keep the builds fast</li><li>Run tests in a clone of the production environment</li><li>Make it easy to get the latest deliverables</li><li>Make build results easy to be monitored by everyone</li><li>Automate deployment</li></ul><h3>Differences Between Each Terminology</h3><ol><li><strong>What are some key differences between Agile and DevOps?</strong></li></ol><p>Basically, DevOps and Agile are complementary to each other. Agile focuses more on the values and principles of developing new software and managing a complex process in a more effective way. Meanwhile, DevOps is all about enhancing the communication, integration, and collaboration between different teams, which comprises the developer and operation teams.</p><p>It takes both Agile and DevOps methods to form a product development life cycle that works seamlessly: Agile principles help shape and steer the development toward the right path and DevOps utilizes the tools to make sure the product is fully delivered to the customers.</p><p><strong>2. What are some differences between continuous integration, continuous delivery, and continuous deployment?</strong></p><p>CI is a practice in which code versions are continuously integrated into a shared repository. This practice ensures that new codes are automatedly tested and that errors are quickly detected and fixed.</p><p>Continuous delivery takes CI one step further by ensuring that after integration, the code base is ready to be released any time, within just a push of a button. Therefore, CI is considered a prerequisite for continuous delivery, the other essential part of the CI/CD pipeline.</p><p>As for continuous deployment, no manual step is required. Once the codes have passed the tests, they are automatically pushed to the production environment.</p><p>All three of these components (continuous integration, continuous delivery, and continuous deployment) are essential phases of implementing DevOps.</p><p>On one hand, continuous delivery is more suitable for applications that already exist with active users so that things can flow a bit slower and be more tuned. On the other hand, if you plan to release brand new software and want the whole process to be fully automated, continuous deployment is a more suitable choice for your product.</p><p><strong>3. What are some fundamental differences between continuous delivery and continuous deployment?</strong></p><p>Under continuous delivery, the codes in the main branch are always ready to be deployed manually. This practice allows the development team to decide when to release new changes or features to best benefit the organization.</p><p>Meanwhile, continuous deployment will have all updates and fixes in the code automatically deployed to the production environment immediately after the testing phase and without any human intervention.</p><p><strong>4. What are the differences between continuous integration and continuous delivery?</strong></p><p>Continuous integration helps ensure that software components work closely together. Integration should be done frequently; preferably on an hourly or daily basis. Continuous integration helps increase the frequency of code commits and reduces the complexity of connecting code from multiple developers. Eventually, this process reduces the chances for non-compatible code and redundant efforts.</p><p>Continuous delivery is the next step in the CI/CD pipeline. As the code is integrated into the shared repository continuously, continuously testing that code is made possible. There are no gaps while waiting for code to be completed before testing can occur. This ensures as many bugs are found as possible to then continuously deliver code to production.</p><p><strong>5. What are the differences between DevOps and continuous delivery?</strong></p><p>DevOps is more of an organizational and cultural approach that promotes collaboration and communication between both the engineering and operation teams.</p><p>Meanwhile, continuous delivery is an essential factor that contributes to the success of implementing DevOps into the product development workflow. Continuous delivery practices help to make new releases more reliable and establish a more seamless and shorter process.</p><p>The key purpose of DevOps is to effectively combine the Dev and Ops roles, remove all silos, and deliver business goals independent of continuous delivery practices.</p><p>Alternatively, continuous delivery works best when there is already a DevOps process in place. Thus, it amplifies collaboration and streamlines the unified product development cycle of the organization.</p><p><strong>6. What are the differences between Agile, Lean IT, and DevOps?</strong></p><p>Agile is a methodology that focuses solely on the development of software. Agile aims to iterate development, establish continuous delivery, shorten feedback loops, and improve team collaboration throughout the software development life cycle (SDLC)</p><p>Lean IT is a methodology that aims to streamline the value stream of the product development cycle. Lean focuses on eliminating unnecessary processes that do not add value and creating a flow to optimize the value streams</p><p>DevOps focuses on both the development and deployment — the Dev and Ops of the product development process. Its goal is to effectively unite the roles between automation tools and IT professionals for a more streamlined and automated process.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5927ce619590" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Docker Interview Questions — Part 1]]></title>
            <link>https://medium.com/@vndmanral1/docker-interview-questions-part-1-c84eee2679bf?source=rss-3602b52ef054------2</link>
            <guid isPermaLink="false">https://medium.com/p/c84eee2679bf</guid>
            <dc:creator><![CDATA[Vinod Manral]]></dc:creator>
            <pubDate>Wed, 07 Dec 2022 06:40:48 GMT</pubDate>
            <atom:updated>2022-12-07T06:40:48.346Z</atom:updated>
            <content:encoded><![CDATA[<h3>Docker Interview Questions — Part 1</h3><h3>Common Questions You should know before the Interview</h3><h3>Docker Interview Questions</h3><p>Docker is getting a lot of traction in the industry because of its performance-savvy and universal replicability architecture while providing the following four cornerstones of modern application development: autonomy, decentralization, parallelism &amp; isolation. Below are the top 50 interview questions for candidates who want to prepare on Docker Container Technology:</p><h3>What are 5 similarities between Docker &amp; Virtual Machine?</h3><p>Docker is not quite like a VM. It uses the host kernel &amp; can’t boot a different operating system. Below are 5 similarities between Docker &amp; Virtual Machine:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/899/0*VB9BcJH4TbyNtZjT.png" /></figure><h3>How is Docker different from Virtual Machine?</h3><p>Figure: Docker Vs VM Below are a list of 6 differences between Docker container &amp; VM:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/739/0*BxuyXwGY_DBGUVRI.png" /></figure><h3>What is the difference between Container Networking &amp; VM Networking?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/941/0*8Kdcc6-av5EKzCzI.png" /></figure><h3>Is it possible to run multiple process inside Docker container?</h3><p>Yes, you can run multiple processes inside a Docker container. This approach is discouraged for most use cases. For maximum efficiency and isolation, each container should address one specific area of concern. However, if you need to run multiple services within a single container, you can use tools like the supervisor. The supervisor is a moderately heavy-weight approach that requires you to package supervisord and its configuration in your image (or base your image on one that includes supervisord), along with the different applications it manages. Then you start supervisord, which manages your processes for you. Example: Here is a Dockerfile using this approach, that assumes the pre-written supervisord.conf, my_first_process, and my_second_process files all exist in the same directory as your Dockerfile.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/974/0*L7beGr2oWpCjFg1e.png" /></figure><h3>Does Docker run on Linux, macOS, and Windows?</h3><p>You can run both Linux and Windows programs and executables in Docker containers. The Docker platform runs natively on Linux (on x86–64, ARM, and many other CPU architectures) and on Windows (x86–64). Docker Inc. builds products that let you build and run containers on Linux, Windows, and macOS.</p><h3>What is DockerHub?</h3><p>DockerHub is a cloud-based registry service that allows you to link to code repositories, build your images and test them, store manually pushed images, and link to Docker cloud so you can deploy images to your hosts. It provides a centralized resource for container image discovery, distribution and change management, user and team collaboration, and workflow automation throughout the development pipeline.</p><h3>What is Dockerfile?</h3><p>Docker builds images automatically by reading the instructions from a text file called Dockerfile. It contains all commands, in order, needed to build a given image. A Dockerfile adheres to a specific format and set of instructions which you can find here.</p><h3>How is Dockerfile different from Docker Compose?</h3><p>A Dockerfile is a simple text file that contains the commands a user could call to assemble an image whereas Docker Compose is a tool for defining and running multi-container Docker applications. Docker Compose defines the services that make up your app in docker-compose.yml so they can be run together in an isolated environment. It gets an app running in one command by just running docker-compose up. Docker compose uses the Dockerfile if one adds the build command to your project’s docker-compose.yml. Your Docker workflow should be to build a suitable Dockerfile for each image you wish to create, then use compose to assemble the images using the build command.</p><h3>Can I use JSON instead of YAML for my Docker Compose file?</h3><p>Yes. YAML is a superset of JSON so any JSON file should be valid Yaml. To use a JSON file with Compose, specify the filename to use, for example docker-compose -f docker-compose.json up</p><p>You can use JSON instead of YAML for your compose file, to use JSON file with compose, specify the filename to use for eg: docker-compose -f docker-compose.json up</p><h3>How to create Docker container?</h3><p>We can use Docker image to create a Docker container by using the below command:</p><pre>$ docker run -t -i command name</pre><p>This command will create and start a container. If you want to verify the list of all running containers with the status on a host uses the below command:</p><pre>$ docker ps -a</pre><h3>What is maximum number of container you can run per host?</h3><p>This really depends on your environment. The size of your applications as well as the amount of available resources (i.e like CPU) will all affect the number of containers that can be run in your environment. Containers unfortunately are not magical. They can’t create new CPU from scratch. They do, however, provide a more efficient way of utilizing your resources. The containers themselves are super lightweight (remember, shared OS vs individual OS per container) and only last as long as the process they are running.</p><h3>Is it possible to have my own private Docker registry?</h3><p>Yes, it is possible today using Docker own registry server. if you want to use 3rd party tool, see Portus. TBA</p><h3>Does Docker container package up the entire OS?</h3><p>Docker containers do not package up the OS. They package up the applications with everything that the application needs to run. The engine is installed on top of the OS running on a host. Containers share the OS kernel allowing a single host to run multiple containers.</p><h3>Describe how many ways are available to configure Docker daemon?</h3><p>There are two ways to configure the Docker daemon:</p><ul><li>Using a JSON configuration file. This is the preferred option, since it keeps all configurations in a single place.</li><li>Using flags when starting dockerd. You can use both of these options together as long as you don’t specify the same option both as a flag and in the JSON file. If that happens, the Docker daemon won’t start and prints an error message. $ dockerd — debug — tls=true — tlscert=/var/docker/server.pem — tlskey=/var/docker/serverkey.pem<br> — host tcp://&lt;Host_IP&gt;:2376</li></ul><ol><li>Can you list reasons why Container Networking is so important? Below are top 5 reasons why we need container networking:</li></ol><ul><li>Containers need to talk to external world.</li><li>Reach Containers from external world to use the service that Containers provides.</li><li>Allows Containers to talk to host machine.</li><li>Inter-container connectivity in same host and across hosts.</li><li>Discover services provided by containers automatically.</li><li>Load balance traffic between different containers in a service.</li><li>Provide secure multi-tenant services.</li></ul><h3>What does CNM refers to? What are its components? ![img](</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/697/0*YeRaZYLhbl-PV6JM.png" /></figure><p>CNM refers to Container Networking Model. The Container Network Model (CNM) is a standard or specification from Docker, Inc. that forms the basis of container networking in a Docker environment.It is Docker’s approach to providing container networking with support for multiple network drivers. The CNM provides the following contract between networks and containers:</p><ul><li>All containers on the same network can communicate freely with each other</li><li>Multiple networks are the way to segment traffic between containers and should be supported by all drivers</li><li>Multiple endpoints per container are the way to join a container to multiple networks</li><li>An endpoint is added to a network sandbox to provide it with network connectivity</li></ul><p>The major components of the CNM are:</p><ul><li>Network,</li><li>Sandbox and</li><li>Endpoint. Sandbox is a generic term that refers to OS specific technologies used to isolate networks stacks on a Docker host. Docker on Linux uses kernel namespaces to provide this sandbox functionality. Networks “stacks” inside of sandboxes include interfaces, routing tables, DNS etc. A network in CNM terms is one or more endpoints that can communicate.All endpoints on the same network can communicate with each other.Endpoints on different networks cannot communicate without external routing.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/908/0*oL5mCnQ1xW0IkQii.png" /></figure><h3>What are different types of Docker Networking drivers?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1004/0*t3uLdMfI7Igv1CXl.png" /></figure><p>Docker’s networking subsystem is pluggable using drivers. Several drivers exist by default, and provide core networking functionality. Below is the snapshot of difference of various Docker networking drivers.</p><p>Below are details of Docker networking drivers: Bridge: The default network driver. If you don’t specify a driver, this is the type of network you are creating. Bridge networks are usually used when your applications run in standalone containers that need to communicate.</p><p>Host: For standalone containers, remove network isolation between the container and the Docker host, and use the host’s networking directly. host is only available for swarm services on Docker 17.06 and higher.</p><p>Overlay: Overlay networks connect multiple Docker daemons together and enable swarm services to communicate with each other. You can also use overlay networks to facilitate communication between a swarm service and a standalone container, or between two standalone containers on different Docker daemons. This strategy removes the need to do OS-level routing between these containers. See overlay networks.</p><p>MacVLAN: Macvlan networks allow you to assign a MAC address to a container, making it appear as a physical device on your network. The Docker daemon routes traffic to containers by their MAC addresses. Using the macvlan driver is sometimes the best choice when dealing with legacy applications that expect to be directly connected to the physical network, rather than routed through the Docker host’s network stack.</p><p>None: For this container, disable all networking. Usually used in conjunction with a custom network driver. none is not available for swarm services.</p><h3>What features are possible only under Docker Enterprise Edition in comparison to Docker Community Edition?</h3><p>The following two features are only possible when using Docker EE and managing your Docker services using Universal Control Plane (UCP): The HTTP routing mesh allows you to share the same network IP address and port among multiple services. UCP routes the traffic to the appropriate service using the combination of hostname and port, as requested from the client. Session stickiness allows you to specify information in the HTTP header which UCP uses to route subsequent requests to the same service task, for applications which require stateful sessions.</p><h3>How is Docker Bridge network different from traditional Linux bridge ?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/974/0*lrBY2jxLaQPc6SZW.png" /></figure><p>In terms of networking, a bridge network is a Link Layer device which forwards traffic between network segments. A bridge can be a hardware device or a software device running within a host machine’s kernel. In terms of Docker, a bridge network uses a software bridge which allows containers connected to the same bridge network to communicate, while providing isolation from containers which are not connected to that bridge network. The Docker bridge driver automatically installs rules in the host machine so that containers on different bridge networks cannot communicate directly with each other.</p><h3>How to create a user-defined Bridge network ?</h3><p>To create a user-defined bridge network, one can use the docker network create command -</p><p>$ docker network create mynet</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/974/0*N_kZ00IJgi4Gju09.png" /></figure><p>You can specify the subnet, the IP address range, the gateway, and other options. See the docker network create reference or the output of docker network create — help for details.</p><h3>How to delete a user-defined Bridge network ?</h3><p>Use the docker network rm command to remove a user-defined bridge network. If containers are currently connected to the network, disconnect them first.</p><p>$ docker network rm mynet</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/974/0*p2U33xkloALI62De.png" /></figure><h3>How to connect Docker container to user-defined bridge network?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/974/0*b4sLC9l9DiL6Ulcy.png" /></figure><p>When you create a new container, you can specify one or more — network flags. This example connects a Nginx container to the my-net network. It also publishes port 80 in the container to port 8080 on the Docker host, so external clients can access that port. Any other container connected to the my-net network has access to all ports on the my-nginx container, and vice versa.</p><pre>$ docker create --name my-nginx \<br>  --network my-net \<br>  --publish 8080:80 \<br>  nginx:latest</pre><p>To connect a running container to an existing user-defined bridge, use the docker network connect command. The following command connects an already-running my-nginx container to an already-existing my-net network:</p><pre>$ docker network connect my-net my-nginx</pre><h3>Does Docker support IPv6?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/589/0*62abRIYlhWZ392wO.png" /></figure><p>Yes, Docker support IPv6. IPv6 networking is only supported on Docker daemons running on Linux hosts.Support for IPv6 address has been there since Docker Engine 1.5 release.To enable IPv6 support in the Docker daemon, you need to edit /etc/docker/daemon.json and set the ipv6 key to true.</p><pre>{<br>  &quot;ipv6&quot;: true<br>}</pre><p>Ensure that you reload the Docker configuration file.</p><pre>$ systemctl reload docker</pre><p>You can now create networks with the--ipv6flag and assign containers IPv6 addresses using the --ip6 flag.</p><h3>Does Docker Compose file format support IPv6 protocol?</h3><p>Yes.</p><h3>How is overlay network different from bridge network?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/897/0*DnXspoElHI-hNyjw.png" /></figure><p>Bridge networks connect two networks while creating a single aggregate network from multiple communication networks or network segments, hence the name bridge. Overlay networks are usually used to create a virtual network between two separate hosts. Virtual, since the network is build over an existing network. Bridge networks can cater to single host, while overlay networks are for multiple hosts.</p><ol><li>What networks are affected when you join a Docker host to an existing Swarm? When you initialize a swarm or join a Docker host to an existing swarm, two new networks are created on that Docker host:</li></ol><ul><li>an overlay network called ingress, which handles control and data traffic related to swarm services. When you create a swarm service and do not connect it to a user-defined overlay network, it connects to the ingress network by default.</li><li>a bridge network called docker_gwbridge, which connects the individual Docker daemon to the other daemons participating in the swarm.</li></ul><h3>How shall you disable the networking stack on a container?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/804/0*0GEQIYstLWlR6TIf.png" /></figure><p>If you want to completely disable the networking stack on a container, you can use the — network none flag when starting the container. Within the container, only the loopback device is created. The following example illustrates this.</p><h3>How can one create MacVLAN network for Docker container?</h3><p>To create a Macvlan network which bridges with a given physical network interface, once can use — driver macvlan with the docker network create command. You also need to specify the parent, which is the interface the traffic will physically go through on the Docker host.</p><pre>$ docker network create -d macvlan \<br>  --subnet=172.16.86.0/24 \<br>  --gateway=172.16.86.1  \<br>  -o parent=eth0 collabnet</pre><h3>Is it possible to exclude IP address from being used in MacVLAN network?</h3><p>If you need to exclude IP addresses from being used in the Macvlan network, such as when a given IP address is already in use, use --aux-addresses:</p><pre>$ docker network create -d macvlan  \<br>  --subnet=192.168.32.0/24  \<br>  --ip-range=192.168.32.128/25 \<br>  --gateway=192.168.32.254  \<br>  --aux-address=&quot;my-router=192.168.32.129&quot; \<br>  -o parent=eth0 collabnet32</pre><h3>Do I lose my data when the container exits?</h3><p>Not at all! Any data that your application writes to disk gets preserved in its container until you explicitly delete the container. The file system for the container persists even after the container halts.</p><h3>Does Docker Enterprise Edition support Kubernetes?</h3><p>Yes, Docker Enterprise Edition(rightly called EE) support Kubernetes. EE 2.0 allows users to choose either Kubernetes or Swarm at the orchestration layer.</p><h3>What is Docker Swarm?</h3><p>Docker Swarm is native clustering for Docker. It turns a pool of Docker hosts into a single, virtual Docker host. Docker Swarm serves the standard Docker API, any tool that already communicates with a Docker daemon can use Swarm to transparently scale to multiple hosts.</p><h3>What is --memory-swap flag?</h3><p>--memory-swap is a modifier flag that only has meaning if --memory is also set. Using swap allows the container to write excess memory requirements to disk when the container has exhausted all the RAM that is available to it. There is a performance penalty for applications that swap memory to disk often.</p><h3>Can you explain different volume mount types available in Docker?</h3><p>There are three mount types available in Docker · Volumes are stored in a part of the host filesystem which is managed by Docker (/var/lib/docker/volumes/ on Linux). Non-Docker processes should not modify this part of the filesystem. Volumes are the best way to persist data in Docker. · Bind mounts may be stored anywhere on the host system. They may even be important system files or directories. Non-Docker processes on the Docker host or a Docker container can modify them at any time. · tmpfs mounts are stored in the host system’s memory only, and are never written to the host system’s filesystem.</p><h3>How to share data among DockerHost?</h3><p>Ways to achieve this when developing your applications. One is to add logic to your application to store files on a cloud object storage system like Amazon S3. Another is to create volumes with a driver that supports writing files to an external storage system like NFS or Amazon S3. Volume drivers allow you to abstract the underlying storage system from the application logic. For example, if your services use a volume with an NFS driver, you can update the services to use a different driver, as an example to store data in the cloud, without changing the application logic.</p><h3>How to Backup, Restore, or Migrate data volumes under Docker container?</h3><p>Steps to Backup a container</p><ul><li>Launch a new container and mount the volume from the dbstore container</li><li>Mount a local host directory as /backup</li><li>Pass a command that tars the contents of the dbdata volume to a backup.tar file inside our /backup directory.</li></ul><p>$ docker run --rm --volumes-from dbstore -v $(pwd):/backup ubuntu tar cvf /backup/backup.tar /dbdata Restore container from backup With the backup just created, you can restore it to the same container, or another that you made elsewhere. For example, create a new container named dbstore2: $ docker run -v /dbdata --name dbstore2 ubuntu /bin/bash</p><p>Then un-tar the backup file in the new container`s data volume:</p><pre>$ docker run --rm --volumes-from dbstore2 -v $(pwd):/backup ubuntu bash -c &quot;cd /dbdata &amp;&amp; tar xvf /backup/backup.tar --strip 1</pre><h3>How to Configure Automated Builds on DockerHub</h3><p>You can build your images automatically from a build context stored in a repository. A build context is a Dockerfile and any files at a specific location. For an automated build, the build context is a repository containing a Dockerfile.</p><h3>How to configure the default logging driver under Docker?</h3><p>To configure the Docker daemon to default to a specific logging driver, set the value of log-driver to the name of the logging driver in the daemon.json file, which is located in /etc/docker/ on Linux hosts or C:\ProgramData\docker\config\ on Windows server hosts. The default logging driver is json-file.</p><h3>Why do my services take 10 seconds to recreate or stop?</h3><p>Compose stop attempts to stop a container by sending a SIGTERM. It then waits for a default timeout of 10 seconds. After the timeout, a SIGKILL is sent to the container to forcefully kill it. If you are waiting for this timeout, it means that your containers aren’t shutting down when they receive the SIGTERM signal.</p><h3>How do I run multiple copies of a Compose file on the same host?</h3><p>Compose uses the project name to create unique identifiers for all of a project’s containers and other resources. To run multiple copies of a project, set a custom project name using the -command line option or the COMPOSE_PROJECT_NAME environment variable.</p><h3>What’s the difference between up, run, and start under Docker Compose?</h3><p>Typically, you want docker-compose up. Use up to start or restart all the services defined in a docker-compose.yml. In the default “attached” mode, you see all the logs from all the containers. In “detached” mode (-d), Compose exits after starting the containers, but the containers continue to run in the background.</p><p>The docker-compose run command is for running “one-off” or “adhoc” tasks. It requires the service name you want to run and only starts containers for services that the running service depends on. Use run to run tests or perform an administrative task such as removing or adding data to a data volume container. The run command acts like docker run -ti in that it opens an interactive terminal to the container and returns an exit status matching the exit status of the process in the container. The docker-compose start command is useful only to restart containers that were previously created, but were stopped. It never creates new containers.</p><h3>What is Docker Trusted Registry?</h3><p>Docker Trusted Registry (DTR) is the enterprise-grade image storage solution from Docker. You install it behind your firewall so that you can securely store and manage the Docker images you use in your applications.</p><h3>How to declare default environment variables under Docker Compose?</h3><p>Compose supports declaring default environment variables in an environment file named .env placed in the folder where the docker-compose command is executed (current working directory). Example: The below example demonstrate how to declare default environmental variable for Docker Compose.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/831/0*JdPFEOSsERHTyghg.png" /></figure><p>When you run docker-compose up, the web service defined above uses the image alpine:v3.4. You can verify this with the docker-compose config command which prints your resolved application config to the terminal:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/974/0*dP2kBAaDxKlVZbkW.png" /></figure><h3>Can you list out ways to share Compose configurations between files and projects under Docker Compose?</h3><p>Compose supports two methods of sharing common configuration:</p><ol><li>Extending an entire Compose file by using multiple Compose files</li><li>Extending individual services with the extends field</li></ol><h3>What is the role of .dockerignore file?</h3><p>To understand the role of .dockerignore file, let us take a practical example. You may have noticed that if you put a Dockerfile in your home directory and launch a docker build you will see a message uploading context. Right? This means docker creates a .tar with all the files in your home and in all the subdirectories, and uploads this tar to the docker daemon. If you have some huge files, this may take a long time. In order to avoid this, you might need to create a specific directory, where you put your Dockerfile, and all what is needed for your build. It becomes necessary to tell docker to ignore some files during the build. Hence, you need to put in the .dockerignore all the files not needed for your build Before the docker CLI sends the context to the docker daemon, it looks for a file named .dockerignore in the root directory of the context. If this file exists, the CLI modifies the context to exclude files and directories that match patterns in it. This helps to avoid unnecessarily sending large or sensitive files and directories to the daemon and potentially adding them to images using ADD or COPY.</p><h3>What is the purpose of EXPOSE command in Dockerfile?</h3><p>When writing your Dockerfiles, the instruction EXPOSE tells Docker the running container listens on specific network ports. This acts as a kind of port mapping documentation that can then be used when publishing the ports.</p><p>EXPOSE &lt;port&gt; [&lt;port&gt;/&lt;protocol&gt;...]</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/974/0*FkSSJTNmC86iHL4A.png" /></figure><p>You can also specify this within a docker run command, such as:</p><p>docker run --expose=1234 my_app</p><p>Please note that EXPOSE will not allow communication via the defined ports to containers outside of the same network or to the host machine. To allow this to happen you need to publish the ports.</p><h3>How is ENTRYPOINT instruction under Dockerfile different from RUN instruction?</h3><p>ENTRYPOINT is meant to provide the executable while CMD is to pass the default arguments to the executable. To understand it clearly, let us consider the below Dockerfile:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/0*3JaOaKQ5I87rG56S.png" /></figure><p>If you try building this Docker image using docker build command -</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/974/0*VI0q3JaVz5TjlNDF.png" /></figure><p>Let us run this image without any argument.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/918/0*FfPfj3MPZeDKktIA.png" /></figure><p>Let’s run it passing a command line argument</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/974/0*bqHm6Lb4L_yk-Vhj.png" /></figure><p>This clearly state that ENTRYPOINT is meant to provide the executable while CMD is to pass the default arguments to the executable.</p><h3>Why Build cache in Docker is so important?</h3><p>If the objects on the file system that Docker is about to produce are unchanged between builds, reusing a cache of a previous build on the host is a great time-saver. It makes building a new container really, really fast. None of those file structures have to be created and written to disk this time — the reference to them is sufficient to locate and reuse the previously built structures.</p><h3>Why Docker Monitoring is necessary?</h3><p>● Monitoring helps to identify issues proactively that would help to avoid system outages. ● The monitoring time-series data provide insights to fine-tune applications for better performance and robustness. ● With full monitoring in place, changes could be rolled out safely as issues will be caught early on and be resolved quickly before that transforms into root-cause for an outage. ● The changes are inherent in container based environments and impact of that too gets monitored indirectly.</p><h3>Difference between Windows Containers and Hyper-V Containers</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/779/0*zNzs5AFJt5R4K2B5.png" /></figure><p>Underlying is the architecture laid out by the Microsoft for the Windows and Hyper-V Containers</p><p>Here are few of the differences between them, Differences:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/866/0*AOHzsHcqe7zQsInT.png" /></figure><h3>What are main difference between Swarm &amp; Kubernetes?</h3><p>Kubernetes is an open-source system for automating deployment, scaling, and management of containerized applications. It was built by Google based on their experience running containers in production using an internal cluster management system called Borg (sometimes referred to as Omega). In the other hand, a Swarm cluster consists of Docker Engine deployed on multiple nodes. Manager nodes perform orchestration and cluster management. Worker nodes receive and execute tasks Below are the major list of differences between Docker Swarm &amp; Kubernetes:</p><p>Applications are deployed in the form of services (or “microservices”) in a Swarm cluster. Docker Compose is a tool which is majorly used to deploy the app. Applications are deployed in the form of a combination of pods, deployments, and services (or “microservices”). Autoscaling feature is not available either in Docker Swarm (Classical) or Docker Swarm Auto-scaling feature is available under K8s. It uses a simple number-of-pods target which is defined declaratively using deployments. CPU-utilization-per-pod target is available.</p><p>Docker Swarm support rolling updates features. At rollout time, you can apply rolling updates to services. The Swarm manager lets you control the delay between service deployment to different sets of nodes, thereby updating only 1 task at a time. Under kubernetes, the deployment controller supports both “rolling-update” and “recreate” strategies. Rolling updates can specify maximum number of pods unavailable or maximum number running during the process. Under Docker Swarm Mode, the node joining a Docker Swarm cluster creates an overlay network for services that span all of the hosts in the Swarm and a host only Docker bridge network for containers. By default, nodes in the Swarm cluster encrypt overlay control and management traffic between themselves. Users can choose to encrypt container data traffic when creating an overlay network by themselves. Under K8s, the networking model is a flat network, enabling all pods to communicate with one another. Network policies specify how pods communicate with each other. The flat network is typically implemented as an overlay.</p><p>Docker Swarm health checks are limited to services. If a container backing the service does not come up (running state), a new container is kicked off. Users can embed health check functionality into their Docker images using the HEALTHCHECK instruction. Under K8s, the health checks are of two kinds: liveness (is app responsive) and readiness (is app responsive, but busy preparing and not yet able to serve) Out-of-the-box K8S provides a basic logging mechanism to pull aggregate logs for a set of containers that make up a pod.</p><h3>Is it possible to run Kubernetes on Docker EE 2.0 Platform?</h3><p>Yes, it is possible to run Kubernetes under Docker EE 2.0 platform. Docker Enterprise Edition (EE) 2.0 is the only platform that manages and secures applications on Kubernetes in multi-Linux, multi-OS and multi-cloud customer environments. As a complete platform that integrates and scales with your organization, Docker EE 2.0 gives you the most flexibility and choice over the types of applications supported, orchestrators used, and where it’s deployed. It also enables organizations to operationalize Kubernetes more rapidly with streamlined workflows and helps you deliver safer applications through integrated security solutions.</p><h3>Can you use Docker Compose to build up Swarm/Kubernetes Cluster?</h3><p>Yes, one can deploy a stack on Kubernetes with docker stack deploy command, the docker-compose.yml file, and the name of the stack. Example: $docker stack deploy — compose-file /path/to/docker-compose.yml mystack $docker stack services mystack You can see the service deployed with the kubectl get services command $kubectl get svc,po,deploy</p><h3>What is ‘docker stack deploy’ command meant for?</h3><p>The ‘docker stack deploy’ is a command to deploy a new stack or update an existing stack. A stack is a collection of services that make up an application in a specific environment. A stack file is a file in YAML format that defines one or more services, similar to a docker-compose.yml file for Docker Compose but with a few extensions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/741/0*VoCweMRUkDFyJ2Ak.png" /></figure><h3>List down major components of Docker EE 2.0?</h3><p>Docker EE is more than just a container orchestration solution; it is a full lifecycle management solution for the modernization of traditional applications and microservices across a broad set of infrastructure platforms. It is a Containers-as-a-Service(CaaS) platform for IT that manages and secures diverse applications across disparate infrastructure, both on-premises and in the cloud. Docker EE provides an integrated, tested and certified platform for apps running on enterprise Linux or Windows operating systems and Cloud providers. It is tightly integrated to the underlying infrastructure to provide a native, easy to install experience and an optimized Docker environment. Docker EE 2.0 GA consists of 3 major components which together enable a full software supply chain, from image creation, to secure image storage, to secure image deployment. ● Universal Control Plane 3.0.0 (application and cluster management) — Deploys applications from images, by managing orchestrators, like Kubernetes and Swarm. UCP is designed for high availability (HA). You can join multiple UCP manager nodes to the cluster, and if one manager node fails, another takes its place automatically without impact to the cluster. ● Docker Trusted Registry 2.5.0 — The production-grade image storage solution from Docker &amp; ● EE Engine 17.06.2- The commercially supported Docker engine for creating images and running them in Docker containers.</p><h3>Explain the concept of HA under Swarm Mode?</h3><p>HA refers to High Availability. High Availability is a feature where you have multiple instances of your applications running in parallel to handle increased load or failures. These two paradigms fit perfectly into Docker Swarm, the built-in orchestrator that comes with Docker. Deploying your applications like this will improve your uptime which translates to happy users. For creating a high availability container in the Docker Swarm, we need to deploy a docker service to the swarm with nginx image. This can be done by using docker swarm create command as specified above.</p><h3>docker service create — name nginx — publish 80:80 nginx</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/645/0*qqpXlt6lVu6KH62j.png" /></figure><h3>Can you explain what is Routing Mesh under Docker Swarm Mode?</h3><p>Routing Mesh is a feature which make use of Load Balancer concepts.It provides global publish port for a given service. The routing mesh uses port based service discovery and load balancing. So to reach any service from outside the cluster you need to expose ports and reach them via the Published Port. Docker Engine swarm mode makes it easy to publish ports for services to make them available to resources outside the swarm. All nodes participate in an ingress routing mesh. The routing mesh enables each node in the swarm to accept connections on published ports for any service running in the swarm, even if there’s no task running on the node. The routing mesh routes all incoming requests to published ports on available nodes to an active container.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/974/0*blWYfeBT3uwEHSq9.png" /></figure><h3>Is Routing Mesh a Load Balancer?</h3><p>Routing Mesh is not Load-Balancer. It makes use of LB concepts.It provides global publish port for a given service. The routing mesh uses port based service discovery and load balancing. So to reach any service from outside the cluster you need to expose ports and reach them via the Published Port. In simple words, if you had 3 swarm nodes, A, B and C, and a service which is running on nodes A and C and assigned node port 30000, this would be accessible via any of the 3 swarm nodes on port 30000 regardless of whether the service is running on that machine and automatically load balanced between the 2 running containers. I will talk about Routing Mesh in separate blog if time permits.</p><h3>Is it possible to run MacVLAN under Docker Swarm Mode? What features does it offer?</h3><p>Starting Docker CE 17.06 release, Docker provides support for local scope networks in Swarm. This includes any local scope network driver. Some examples of these are bridge, host, and macvlan though any local scope network driver, built-in or plug-in, will work with Swarm. Previously only swarm scope networks like overlay were supported.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/974/0*4NsFaaSgrSAXaYGH.png" /></figure><p>MACVLAN offers a number of unique features and capabilities. It has positive performance implications by virtue of having a very simple and lightweight architecture. It’s use cases includes very low latency applications and networking design that requires containers be on the same subnet as and using IPs as the external host network.The macvlan driver uses the concept of a parent interface. This interface can be a physical interface such as eth0, a sub-interface for 802.1q VLAN tagging like eth0.10 (.10 representing VLAN 10), or even a bonded host adaptor which bundles two Ethernet interfaces into a single logical interface.</p><h3>What are Docker secrets and why is it necessary</h3><p>In Docker there are three key components to container security and together they result in inherently safer apps.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/974/0*3i4EWjDC4-XSIICE.png" /></figure><p>Docker Secrets, a container native solution that strengthens the Trusted Delivery component of container security by integrating secret distribution directly into the container platform. By integrating secrets into Docker orchestration, we are able to deliver a solution for the secrets management problem that follows these exact principles. The following diagram provides a high-level view of how the Docker swarm mode architecture is applied to securely deliver a new type of object to our containers: a secret object.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/974/0*-h07S3dY_NSDOS7o.png" /></figure><p>.</p><h3>Serverless Interview Questions</h3><h3>What is Serverless and why is it important?</h3><p>Serverless allows you to build and run applications and services without thinking about servers. It eliminates infrastructure management tasks such as server or cluster provisioning, patching, operating system maintenance, and capacity provisioning. You can build them for nearly any type of application or backend service, and everything required to run and scale your application with high availability is handled for you.</p><h3>Why use serverless?</h3><p>Serverless enables you to build modern applications with increased agility and lower total cost of ownership. Building serverless applications means that your developers can focus on their core product instead of worrying about managing and operating servers or runtimes, either in the cloud or on-premises. This reduced overhead lets developers reclaim time and energy that can be spent on developing great products which scale and that are reliable.</p><h3>What are the benefits of serverless?</h3><ul><li>NO SERVER MANAGEMENT</li></ul><p>There is no need to provision or maintain any servers. There is no software or runtime to install, maintain, or administer</p><ul><li>FLEXIBLE SCALING</li></ul><p>Your application can be scaled automatically or by adjusting its capacity through toggling the units of consumption (e.g. throughput, memory) rather than units of individual servers.</p><ul><li>PAY FOR VALUE</li></ul><p>Pay for consistent throughput or execution duration rather than by server unit.</p><ul><li>AUTOMATED HIGH AVAILABILITY</li></ul><p>Serverless provides built-in availability and fault tolerance. You don’t need to architect for these capabilities since the services running the application provide them by default.</p><h3>Tell something about the AWS Serverless Platform?</h3><p>AWS provides a set of fully managed services that you can use to build and run serverless applications. Serverless applications don’t require provisioning, maintaining, and administering servers for backend components such as compute, databases, storage, stream processing, message queueing, and more. You also no longer need to worry about ensuring application fault tolerance and availability. Instead, AWS handles all of these capabilities for you. This allows you to focus on product innovation while enjoying faster time-to-market.</p><h3>COMPUTE</h3><h3>AWS Lambda</h3><p>AWS Lambda lets you run code without provisioning or managing servers. You pay only for the compute time you consume — there is no charge when your code is not running.</p><h3>AWS Fargate</h3><p>AWS Fargate is a purpose-built serverless compute engine for containers. Fargate scales and manages the infrastructure required to run your containers.</p><h3>STORAGE</h3><p>Amazon Simple Storage Service (Amazon S3) provides developers and IT teams with secure, durable, highly-scalable object storage. Amazon S3 is easy to use, with a simple web service interface to store and retrieve any amount of data from anywhere on the web.</p><h3>Amazon Elastic File System (Amazon EFS)</h3><p>It provides simple, scalable, elastic file storage. It is built to elastically scale on demand, growing and shrinking automatically as you add and remove files.</p><h3>DATA STORES</h3><p>Amazon DynamoDB is a fast and flexible NoSQL database service for all applications that need consistent, single-digit millisecond latency at any scale.</p><h3>API PROXY</h3><p>Amazon API Gateway is a fully managed service that makes it easy for developers to create, publish, maintain, monitor, and secure APIs at any scale. It offers a comprehensive platform for API management. API Gateway allows you to process hundreds of thousands of concurrent API calls and handles traffic management, authorization and access control, monitoring, and API version management.</p><h3>APPLICATION INTEGRATION</h3><p>Amazon SNS is a fully managed pub/sub messaging service that makes it easy to decouple and scale microservices, distributed systems, and serverless applications.</p><h3>ORCHESTRATION</h3><p>AWS Step Functions makes it easy to coordinate the components of distributed applications and microservices using visual workflows. Building applications from individual components that each perform a discrete function lets you scale and change applications quickly. Step Functions is a reliable way to coordinate components and step through the functions of your application.</p><h3>ANALYTICS</h3><p>Amazon Kinesis is a platform for streaming data on AWS, offering powerful services to make it easy to load and analyze streaming data, and also providing the ability for you to build custom streaming data applications for specialized needs.</p><h3>DEVELOPER TOOLING</h3><p>AWS provides tools and services that aid developers in the serverless application development process. AWS and its partner ecosystem offer tools for continuous integration and delivery, testing, deployments, monitoring and diagnostics, SDKs, frameworks, and integrated development environment (IDE) plugins.</p><h3>DCA Mock questions</h3><h3>1. How can we limit the number of CPUs provided to a container?</h3><p>a) Using --cap-add CPU .<br>b) Using --cpuset-cpus .<br>c) Using--cpus.<br>d) It is not possible to specify the number of CPUs;we have to use --cpu-shares and define the CPU slices.</p><h3>2. How can we limit the amount of memory available to a container?</h3><p>a) It is not possible to limit the amount of memory available to a container.<br>b) Using --cap-drop MEM .<br>c) Using --memory .<br>d) Using --memory-reservation .</p><h3>3.What environment variables should be exported to start using a trusted environment with the Docker client?</h3><p>a) export DOCKER_TRUSTED_ENVIRONMENT=1<br>b) export DOCKER_CONTENT_TRUST=1<br>c) export DOCKER_TRUST=1<br>d) export DOCKER_TRUSTED=1</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c84eee2679bf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to automate your DevOps using GitLab CI/CD + Docker + Ansible]]></title>
            <link>https://medium.com/@vndmanral1/how-to-automate-your-devops-using-gitlab-ci-cd-docker-ansible-141aaeae5672?source=rss-3602b52ef054------2</link>
            <guid isPermaLink="false">https://medium.com/p/141aaeae5672</guid>
            <dc:creator><![CDATA[Vinod Manral]]></dc:creator>
            <pubDate>Mon, 25 Apr 2022 08:17:07 GMT</pubDate>
            <atom:updated>2022-11-15T08:30:18.883Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*sTDOpyGCG_wvotzn.png" /></figure><p>I create an independent deployment image because first it allows to have the ssh keys inside a specific project and it makes it more secure and second, common configurations and dependency installations could be done inside of this image which causes the main product CI/CD to start faster.</p><p>First, create a GitLab project named deployment and put the below files inside it.</p><p>File .gitlab-ci.yml</p><pre>image: docker:19.03.13stages:build_docker_image:<br>variables:<br> - build <br> stage: build <br> before_script: <br> - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY<br> script:<br> - docker build --build-arg PRODUCTION_PRIVATE_KEY=$PRODUCTION_PRIVATE_KEY --build-arg STAGING_PRIVATE_KEY=$STAGING_PRIVATE_KEY -t $CONTAINER_IMAGE .<br> - docker push $CONTAINER_IMAGE <br> DOCKER_TLS_CERTDIR: &quot;/certs&quot;<br> CONTAINER_IMAGE: $CI_REGISTRY_IMAGE:latest</pre><p>File Dockerfile</p><pre>FROM python:3ADD ./ansible /deploy/ansibleRUN apt-get update &amp;&amp; apt-get install sshpass -y &amp;&amp; apt-get clean<br>RUN pip install ansible <br>WORKDIR /deploy/ansible <br>ARG STAGING_PRIVATE_KEY<br>ARG PRODUCTION_PRIVATE_KEY<br>RUN mkdir -p /root/.ssh<br>RUN echo &quot;$STAGING_PRIVATE_KEY&quot; | base64 -d | tr -d &#39;\r&#39; &gt; /root/.ssh/staging<br>RUN echo &quot;$PRODUCTION_PRIVATE_KEY&quot; | base64 -d | tr -d &#39;\r&#39; &gt; /root/.ssh/production<br>RUN chmod 400 /root/.ssh/staging<br>RUN chmod 400 /root/.ssh/production<br>ADD ./entrypoint.sh /deploy/entrypoint.sh<br>ENTRYPOINT [&quot;/deploy/entrypoint.sh&quot;] <br>RUN ansible-galaxy collection install community.general</pre><p>File entrypoint.sh</p><pre>#!/bin/bash<br>set -e<br>eval $(ssh-agent -s)<br>ssh-add /root/.ssh/staging<br>if [ ! -z &quot;$PRODUCTION_PASSPHRASE&quot; ]; then<br> echo &#39;echo $PRODUCTION_PASSPHRASE&#39; &gt; /root/.ssh/.tty_echo &amp;&amp; chmod 700 /root/.ssh/.tty_echo<br> cat /root/.ssh/production | SSH_ASKPASS=/root/.ssh/.tty_echo DISPLAY=1 ssh-add -<br>fi<br>exec &quot;$@&quot;</pre><p>File ansible/ansible.cfg</p><pre>[defaults]<br>error_on_undefined_vars = true<br>host_key_checking = False</pre><p>File ansible/hosts</p><pre>[all:vars][server1][server2]<br>ansible_connection=ssh<br>production1 ansible_host=s1.example.com<br>production2 ansible_host=s2.example.com<br>staging2 ansible_host=staging.s2.example.com <br>staging1 ansible_host=staging.s1.example.com <br>ansible_user=root<br>ansible_python_interpreter=/usr/bin/python3</pre><p>File ansible/deploy.yml</p><pre>- hosts: &quot;{{target}}&quot;- name: Prints some debug info- name: copy required dirs from source to remote- name: copy required files from source to remote- name: login to registry- name: make service up<br> gather_facts: yes<br> ansible.builtin.debug:<br> copy:<br> template:<br> community.general.docker_login:<br> community.general.docker_compose:<br> project_src: &quot;{{project_dest}}&quot;<br> pull: yes<br> recreate: always<br> state: present<br> - name: Log out of registry<br> community.general.docker_login:<br> state: absent <br> registry_url: &quot;{{lookup(&#39;env&#39;,&#39;CI_REGISTRY&#39;) | default(lookup(&#39;env&#39;,&#39;REGISTRY_URL&#39;),true) | default(REGISTRY_URL,true)}}&quot;<br> username: &quot;{{lookup(&#39;env&#39;,&#39;CI_REGISTRY_USER&#39;) | default(lookup(&#39;env&#39;,&#39;REGISTRY_USERNAME&#39;),true) | default(REGISTRY_USERNAME,true)}}&quot;<br> password: &quot;{{lookup(&#39;env&#39;,&#39;CI_REGISTRY_PASSWORD&#39;) | default(lookup(&#39;env&#39;,&#39;REGISTRY_PASSWORD&#39;),true) | default(REGISTRY_PASSWORD,true)}}&quot;<br> state: present <br> src: &quot;{{project_src}}/{{item.split(&#39;:&#39;)[0]}}&quot;<br> dest: &quot;{{item.split(&#39;:&#39;)[1] if (item.split(&#39;:&#39;)|length)&gt;1 and item.split(&#39;:&#39;)[1]!=&#39;&#39; else project_dest}}/{{item.split(&#39;:&#39;)[0]}}&quot;<br> loop: &quot;{{copy_file_list}}&quot;<br> when: item!=&#39;&#39; <br> src: &quot;{{project_src}}/{{item.split(&#39;:&#39;)[0]}}&quot;<br> dest: &quot;{{item.split(&#39;:&#39;)[1] if (item.split(&#39;:&#39;)|length)&gt;1 and item.split(&#39;:&#39;)[1]!=&#39;&#39; else (project_dest+&#39;/&#39;+item.split(&#39;:&#39;)[0])}}&quot;<br> loop: &quot;{{copy_dir_list}}&quot;<br> when: item!=&#39;&#39; <br> msg:<br> - &quot;project source: {{ project_src }}&quot;<br> - &quot;project destination: {{ project_dest }}&quot;<br> <br> - name: create directory in remote<br> file:<br> name: &quot;{{project_dest}}&quot;<br> state: directory <br> tasks:<br> - name: set facts<br> set_fact:<br> copy_file_list: &quot;{{ (copyFileList|default(&#39;&#39;,true)).split(&#39;,&#39;) + [&#39;docker-compose.yml&#39; ] }}&quot;<br> copy_dir_list: &quot;{{ (copyDirList|default(&#39;&#39;,true)).split(&#39;,&#39;) }}&quot;<br> project_src: &quot;{{lookup(&#39;env&#39;,&#39;CI_PROJECT_DIR&#39;)}}&quot;<br> project_dest: &quot;/root/compose/{{lookup(&#39;env&#39;,&#39;PROJECT_DIRECTORY&#39;) | default(lookup(&#39;env&#39;,&#39;CI_PROJECT_NAME&#39;),true) | default(&#39;unknown&#39;,true)}}&quot;</pre><p>Now for this setup to work we need to have some ssh keys. Run the below commands to create your ssh keys for the staging and production environment:</p><pre>ssh-keygen -b 2048 -t rsa -f staging -q -N &quot;&quot;<br>ssh-keygen -b 2048 -t rsa -f production -q -N &quot;some_long_password&quot;</pre><p>replace some_long_password with your password and run them. These will create 4 files on your current directory. staging staging.pub production production.pub.you need to copy content of .pub ones to your servers in file /root/.ssh/authorized_keys. Create a directory or file if not exists. Also, note that you need to copy staging.pub to staging servers and production.pub to production servers.</p><p>Now run the below commands:</p><pre>cat staging | base64 &gt; staging.base64<br>cat production | base64 &gt; production.base64</pre><p>These commands encode your ssh key with base 64. This allows us to easily put them in GitLab CI/CD variables and mask them. In your deployment repository go to <strong><em>setting &gt; CI/CD &gt; Variables</em></strong> and press Add variable in the key field write STAGING_PRIVATE_KEY and in value copy content of staging.base64 file. Also, check Masked variable. Do the same for production but also checked Protect variable. There are some good explanations of what are masked and protected variables in that dialog.</p><p>Now we have a complete setup. Just push your codes to the repository and let its CI/CD pipeline get done. After it is finished go to <strong><em>Packages &amp; Registries &gt; Container Registry</em></strong> find the image with the tag latest there and copy its path. We need this path to reference the image later. For simplicity, you can add a global CI/CD variable that holds this path. You need to login as a GitLab admin user and go to <strong><em>menu &gt; admin &gt; Settings &gt; CI/CD &gt; Variables</em></strong> and create a variable there. I created a variable with the key DEPLOYMENT_IMAGE and the value of the mentioned path. If you don&#39;t have access you should do it in your main product repository.</p><p>In this section, I go inside each file and explain it a bit.</p><p><strong>.gitlab-ci.yml:</strong> In this file, we just create a script to run as CI/CD of our deployment repository. The most important line here is</p><pre>docker build --build-arg PRODUCTION_PRIVATE_KEY=$PRODUCTION_PRIVATE_KEY --build-arg STAGING_PRIVATE_KEY=$STAGING_PRIVATE_KEY -t $CONTAINER_IMAGE .</pre><p>This line creates a docker imaged using Dockerfile we provide. It also imputed two environment variables $PRODUCTION_PRIVATE_KEY and $STAGING_PRIVATE_KEY to our Dockerfile. After the build, the deployment image will be pushed to the GitLab container registry. We can observe it in <strong><em>Packages &amp; Registries &gt; Container Registry</em></strong>.</p><p><strong>Dockerfile:</strong> This file is the recipe to build a docker image. Our docker image is based on python3. We install Ansible and its requirement. With the ADD command we put the content of the ./ansible directory of our repository to the /deploy/ansible directory of our image. Later I install sshpass. We need it for providing the password to our password-protected production key. Other lines till the entrypoint line will copy the ssh keys we put in CI/CD variables to the docker image and make them usable by changing their permissions. 400 means only read permission for the owner. And finally, we copied an entrypoint script.</p><p><strong>entrypoint.sh:</strong> This script will be run whenever we start our docker container. For our case before other CI/CD get started. eval $(ssh-agent -s) will run ssh-agent on a different process. ssh-agent is a key management tool that is used later by ssh-add command. On the 4th line, we simply add the staging ssh key to our key management tool. But for production, we first need to check if the production passphrase is provided or not. If it is not provided we don&#39;t need to add its key. The use case is when we want to deploy a product to staging server using the development branch of its repository. In that condition, we don&#39;t have any production passphrase. At the end exec &quot;$@&quot; will continue to run any command provided to this docker image. This will allow other CI/CDs to use the deployment image as their image.</p><p><strong>ansible/ansible.cfg:</strong> It is not much here. Just some ansible configuration which you can google.</p><p><strong>ansible/hosts: </strong>In the first of these files ([all:vars] section) we defined our server configurations, like the method of connection which is ssh, and ssh user which is root. Then on [serverX] sections we introduce our servers with their addresses and network interfaces. productionX and stagingX are our main VPSs which we grouped in serverX which is a physical server. If you have a different topology you can change this structure. It’s something optional. Of course, example.com is a sample domain. You need to replace it with your domains. You can use IPs but I strongly recommend using domains.</p><p><strong>ansible/deploy.yml: </strong>I don’t go very deep inside this playbook but it generally does the following actions. It copies the docker-compose.yml file from the main product repository. We can also define copyFileList and copyDirList as comma-separated variables of our main prodouct repository. These files and directories will be copied too. The destination is a bit tricky. The default destination is /root/compose/{main product repository name} but there are some ways in this code to customize it. As a homework find it yourself :)</p><p><a href="https://medium.com/@a.golmirzaei/how-to-automate-your-devops-using-gitlab-ci-cd-docker-ansible-part2-69257e1033e2">Configure CI/CD of the main product repository</a></p><p><em>Originally published at </em><a href="https://medium.com/@a.golmirzaei/how-to-automate-your-devops-using-gitlab-ci-cd-docker-ansible-a32de7a116fc"><em>https://medium.com</em></a><em> on April 25, 2022.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=141aaeae5672" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>